Combining two fields

C

Claire

I'm trying to combine two fields in a particular way, and am trying to write
a function to do so. However, I'm getting caught up in how to actually grab
the contents of the fields. I've tried going the DAO route, which I think
was misguided anyway, and am now trying to get to them directly from the
table. The following function should manipulate the values of the the two
fields in the specific table into a new string.

Function fCombineSemis(strTable As String, _
strFirstField As String, _
strSecondField As String) _
As String

For example: tblTest:
Days Sites
1/1/09;2/3/09;3/7/09 A;B;C

fCombineSemis("tblTest","Days","Sites")=
1/1/09;A;2/3/09;B;3/7/09;C

I'm pretty sure I have the concatening and looping all set if I can set the
value of the field to a string in the function, but that's where I'm stuck.

I feel like this is obvious and should be staring me right in the face.

Thank you for any help you have!
~Claire
 
A

anlu

Hi Claire,

Could you use something like this:

Function fCombineSemis(strTable As String, _
strFirstField As String, _
strSecondField As String) _
As String
Dim sql As String
Dim rs As Recordset
Dim res

sql = "SELECT " & strFirstField & " & ';' & " & strSecondField & " FROM
" & strTable

Set rs = CurrentDb.OpenRecordset(sql)
Do While Not rs.EOF
res = res & rs(0) & ";"
rs.MoveNext
Loop

fCombineSemis = res
End Function


Regards,
anlu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top