Access 2007
I am trying to create a user defined function to parse name fields in a query. The code below is a simple task used to establish quick and simple test code. The function works, but will not move beyond the first record. It executes the first record and appears to use the first record as though copy and paste… Is there a way to step through each record?
My query field is: xName: Test2()
My code:
Function Test2()
Dim rst As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb
Set rst = db.OpenRecordset("tblSample1")
If Not (rst.BOF And rst.EOF) Then
Test2 = StrConv(rst![lastname], vbProperCase)
Else
rst.MoveNext
End If
rst.Close
Set db = Nothing
End Function
I am trying to create a user defined function to parse name fields in a query. The code below is a simple task used to establish quick and simple test code. The function works, but will not move beyond the first record. It executes the first record and appears to use the first record as though copy and paste… Is there a way to step through each record?
My query field is: xName: Test2()
My code:
Function Test2()
Dim rst As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb
Set rst = db.OpenRecordset("tblSample1")
If Not (rst.BOF And rst.EOF) Then
Test2 = StrConv(rst![lastname], vbProperCase)
Else
rst.MoveNext
End If
rst.Close
Set db = Nothing
End Function