|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Lookup Not Working
I am attempting to use DLookup in following code. I do not get an error message
but the code will work if I actually place my username as the text. I need to have it be a variable though. Please help. Also, thought I read something the other day that the DLookup is not the best option anymore. What should I be using instead? Thanks. Private Sub Form_Load() Dim strName As String Dim varCheck As Variant varCheck = fOSUserName 'This is a function that does work fine MsgBox "Username is " & varCheck 'This msgbox works fine If varCheck <> vbNullString Then 'I am looking for the autonumber of the employee here strName = Nz(DLookup("[PerAuto]", "tblPersonnel", "[NetworkName]= ' " & varCheck & "'"), 0) If strName = 0 Then DoCmd.Close "frmPayroll" Else Me!cboEmployee = strName End If Else DoCmd.Close "frmPrePayroll" End If End Sub |
|
#2
|
|||
|
|||
|
Hi BetsyBean,
My apologies, I missed your post. Your syntax has a space in the quotes for your criteria strName = Nz(DLookup("[PerAuto]", "tblPersonnel", "[NetworkName]= ' " & varCheck & "'"), 0) Remove the space in the quote after [NetworkName] to like this strName = Nz(DLookup("[PerAuto]", "tblPersonnel", "[NetworkName]= '" & varCheck & "'"), 0) This will get what you are looking for. lwells |
|
#3
|
|||
|
|||
|
Thanks
Thanks - that was the problem and I can't believe how much difference one space can make.
|
![]() |
| Viewing: Dev Articles Community Forums > Databases > Microsoft Access Development > Lookup Not Working |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|