Hi:
I have a public function that is supposed to concatenate several field values into one string. For example if:
JobNo = 12345
Jobtype = priority, hold
PartNo = 67
Shape = round
Then I want to concatenate as follows:
12345/priority/67/round
12345/hold/67/round
There should be two rows because there are two different Jobtypes for the same JobNo. The code follows:
Originally, I could not get the function to build the string. I added:
to the function above just to see what it would do. It works - sort of.
When I add:
to the SQL statement that actually calls the function, the function runs but a parameter box pops up and I have to populate it with text. I know this is not running correctly, and I am not sure why.
Right now, the code returns 1 record only after I enter the ambiguous text in the parameter box. Then it fails to put the second row of data together. Instead, it is repeating the first concatenation.
I appreciate any help you guys can provide.
thanks,
Ben
I have a public function that is supposed to concatenate several field values into one string. For example if:
JobNo = 12345
Jobtype = priority, hold
PartNo = 67
Shape = round
Then I want to concatenate as follows:
12345/priority/67/round
12345/hold/67/round
There should be two rows because there are two different Jobtypes for the same JobNo. The code follows:
Code:
Public Function GetJobType(strMyString As String) As _ String
'Declare variables
Dim Db As DAO.Database, rs As DAO.Recordset, sql As _ String
Set db = CurrentDb
sql = "SELECT tblSchedule.JobNo, tblSchedule.JobType, "
sql = sql & "tblSchedule.PartNo, tblSchedule.Shape "
sql = sql & "FROM tblSchedule"
Set rs = db.OpenRecordset(sql, dbOpenDynaset, _
dbSeeChanges)
rs.MoveFirst
strMyString = ""
Do Until rs.EOF
strMyString = rs.Fields("JobNo") & "/"
strMyString = strMyString & rs.Fields("JobType")
strMyString = strMyString & "/" & rs.Fields("PartNo")
strMyString = strMyString & "/" & rs.Fields(Shape)
strMyString = strMyString & vbCrLf
rs.MoveNext
Loop
GetJobType = Format(strMyString, Text)
db.Close
Set rs = Nothing
End Function
Originally, I could not get the function to build the string. I added:
Code:
GetJobType = Format(strMyString, Text)
When I add:
Code:
, GetJobType([strMyString]) AS JobTypeData, "
to the SQL statement that actually calls the function, the function runs but a parameter box pops up and I have to populate it with text. I know this is not running correctly, and I am not sure why.
Right now, the code returns 1 record only after I enter the ambiguous text in the parameter box. Then it fails to put the second row of data together. Instead, it is repeating the first concatenation.
I appreciate any help you guys can provide.
thanks,
Ben