VBA Query

D

dht

I have this code that is suppose to join to fields together and put the
result in the field.

The problem is that I get a message that is a compile error.

Set gdbs = CurrentDb()
Set grst1 = gdbs.openrecordset(Products)
grst1.MoveFirst
grst1.MoveLast
grst1.MoveFirst
Select Case grst1.RecordCount
Case 0
Case Else
For gintloop1 = 1 To grst1.Recordset
With grst1
.edit
!Session_ID = !Windows_Login & " " & !Date
.Update
End With
grst1.MoveNext
Next
End Select
grst1.Close
gdbs.Close

Can anyone point me in the right correction for correcting this code.

Thanks
David
 
D

David M. Williams

dht said:
I have this code that is suppose to join to fields together and put the
result in the field.
The problem is that I get a message that is a compile error.
For gintloop1 = 1 To grst1.Recordset

Could this be the line? Perhaps you mean

For gintloop1 = 1 to grst1.RecordCount

Otherwise, do you get a message indicating where the error occurs?

Can you add an "on error ....." and print error$ to display the error
message?
 
V

Van T. Dinh

Your check for empty Recordset and with Recordset, you normally use While
rather than For loop.

Try something like:

(DAO Library must be inncluded in the References)

****Untested****
Dim gdbs As DAO.Database
Dim grst1 As DAO.Recordset

Set gdbs = CurrentDb()
Set grst1 = gdbs.OpenRecordset(Products)

With grst1
If .RecordCount > 0 Then
.MoveFirst
Do
.Edit
.Fields("Session_ID") = {Not sure what you are doing here}
.Update
.MoveNext
Loop Until .EOF = True
End If
End With

grst1.Close

Set grst1 = Nothing
Set gdbs = Nothing
********

BTW, if you get a Compile error, you should note on the post *which* line
has the Compile error.
 
Top