Question : How do you combine 2 fields and seperate it with a comma?

What I need to do is combine the Last_Name and First_Name into one field, seperated by a comma. Changing my code would be very helpful. Thanks
---------------------------------------------------------------------------------------------------------------
10MAR          RANGEL               MIGUEL                      E                113.29999                  2497
10ORS          SOTO                    OSCAR                      E                1    91.5                      2497
10ORS          SOTO                    OSCAR                      E                22.400000                  2497
10VJA           ADAME                 VICTOR                     E                167.60000                  2497
11DRM           MELSON               DAVID                       E                177.59999                    381
11DRM           MELSON               DAVID                       E                232.70000                    381
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
INSERT INTO Paychex ( User_Name, Last_Name, First_Name, Earnings_Code, Hours_Worked, Store_Id )
SELECT dbo_User_Tb.User_Name, dbo_Employee_Tb.Last_Name, dbo_Employee_Tb.First_Name, IIf([Earnings_Id]="9000","1","2") AS Earnings_Code, Sum(dbo_Payroll_Hours_Tb.Hours_Worked) AS SumOfHours_Worked, dbo_Payroll_Hours_Tb.Store_Id
FROM (dbo_Payroll_Hours_Tb INNER JOIN dbo_Employee_Tb ON dbo_Payroll_Hours_Tb.Employee_Id = dbo_Employee_Tb.Employee_Id) INNER JOIN dbo_User_Tb ON dbo_Employee_Tb.User_Id = dbo_User_Tb.User_Id
WHERE (((dbo_Payroll_Hours_Tb.Pay_Period_End_Date)=[Enter payroll ending date:]))
GROUP BY dbo_User_Tb.User_Name, dbo_Employee_Tb.Last_Name, dbo_Employee_Tb.First_Name, IIf([Earnings_Id]="9000","1","2"), dbo_Payroll_Hours_Tb.Store_Id;
 
----------------------------------------------------------------------------------------------------------------
 
Option Compare Database
 
Public Function CreateTextFile()
Dim strUser_Name As String * 6
Dim strLast_Name As String * 25
Dim strFirst_Name As String * 25
Dim strFiller1 As String * 6
Dim strFiller2 As String * 13
Dim strE As String * 3
Dim strEarnings_Code As String * 17
Dim strHours_Worked As String * 8
Dim strFiller3 As String * 14
Dim strStore_Id As String * 12
Dim strSecurity_Role_Id As String * 25
Dim mydb As DAO.Database, myset As DAO.Recordset
Dim intFile As Integer
 
Set mydb = CurrentDb()
Set myset = mydb.OpenRecordset("Paychex", dbOpenTable)
intFile = FreeFile
 
Open "c:\1753_TA.txt" For Output As intFile
 
Do Until myset.EOF
LSet strUser_Name = myset![User_Name]
RSet strLast_Name = myset![Last_Name]
RSet strFirst_Name = myset![First_Name]
RSet strFiller1 = myset![Filler1]
RSet strFiller2 = myset![Filler2]
RSet strE = myset![E]
RSet strEarnings_Code = myset![Earnings_Code]
RSet strHours_Worked = myset![Hours_Worked]
RSet strFiller3 = myset![Filler3]
RSet strStore_Id = myset![Store_Id]
Print #intFile, strUser_Name & strLast_Name & strFirst_Name & strFiller1 & strFiller2 & strE & strEarnings_Code & strHours_Worked & strFiller3 & strStore_Id
myset.MoveNext
Loop
 
Close intFile
myset.Close
mydb.Close
MsgBox "This Is The Broadbase Version!"
 
 
End Function

Answer : How do you combine 2 fields and seperate it with a comma?

Another approach that's a little more readable might be something like this.  Create a new field that is the combination of the first and last names, and then use it in the PRINT.  Hopefully this gives you the idea:

Dim strFull_Name As String * 25

strFull_Name = TRIM(strLast_Name) & ', ' & TRIM(strFirst_Name)

Print #intFile, strUser_Name & strFull_Name & strFiller1 & strFiller2 & strE & strEarnings_Code & strHours_Worked & strFiller3 & strStore_Id

~bp
Random Solutions  
 
programming4us programming4us