G
Guest
I am using the following code to read in the username logged onto the system
and then am trying to match that value to a lookup table to populate a field
on a form.
Dim User, UserName, stSQL As String
Dim RS, Con As Object
'get username from system
User = VBA.Environ("username")
'Match username to tblFCStaff
Set Con = Application.CurrentProject.Connection
stSQL = "SELECT * from [tblFCStaff] WHERE [logon]= " & User & ";"
Set RS = CreateObject("ADODB.Recordset")
With RS
.ActiveConnection = Con
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Source = stSQL
.Open
.ActiveConnection = Nothing
End With
' If there are no matches, display a message.
If (RS.EOF) Then
Me![OptionLabel1].Visible = True
Else
Me![cboLookup] = RS![Staff]
End If
' Close the recordset and the database.
RS.Close
Set RS = Nothing
Set Con = Nothing
When I run this, I get an error. I stepped through the code and it seems to
be bombing out in the "with RS...it goes fine until it gets to ".Open" and
then it errors out with "No value given for one or more required parameters."
Any idea what is wrong here? I am stumped!
Thanks!
and then am trying to match that value to a lookup table to populate a field
on a form.
Dim User, UserName, stSQL As String
Dim RS, Con As Object
'get username from system
User = VBA.Environ("username")
'Match username to tblFCStaff
Set Con = Application.CurrentProject.Connection
stSQL = "SELECT * from [tblFCStaff] WHERE [logon]= " & User & ";"
Set RS = CreateObject("ADODB.Recordset")
With RS
.ActiveConnection = Con
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Source = stSQL
.Open
.ActiveConnection = Nothing
End With
' If there are no matches, display a message.
If (RS.EOF) Then
Me![OptionLabel1].Visible = True
Else
Me![cboLookup] = RS![Staff]
End If
' Close the recordset and the database.
RS.Close
Set RS = Nothing
Set Con = Nothing
When I run this, I get an error. I stepped through the code and it seems to
be bombing out in the "with RS...it goes fine until it gets to ".Open" and
then it errors out with "No value given for one or more required parameters."
Any idea what is wrong here? I am stumped!
Thanks!