Wrox Programmer Forums
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 24th, 2006, 01:59 PM
Authorized User
Join Date: Aug 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help with DLookup

Can some one please help me with; I'm new to this...

If Me.txtPassword = DLookup("strUserPassword", "tblUsers", "[AidUser]=" & txtNetUser.Value) Then
AidUser = Me.txtNetUser.Value

DoCmd.Close acForm, "frmStartup", acSaveNo
DoCmd.OpenForm "frmUnitSelect"
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
End If

***Background Info:***
-txtPassword is a Text Box for User Passwords
-strUserPassword is a Field in tblUsers
-AidUser is an Autonumber field
-txtNetUser is a text box that autofills the user name from seperate Function
Old August 28th, 2006, 10:16 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG


If nz(Me.txtPassword, "None Supplied") = Nz(DLookup("[strUserPassword]", "tblUsers", "[AidUser] = '" & Me.txtNetUser & "'"),"None Found") Then

First, if the password is a string, you need the single quote delimiter ' in the DLookUp.

Second, I used the Nz function so that if nothing is supplied and/or nothing is found, you get no runtime error messages, but the "password" is rejected and you still get your rejection message.

Oh, and welcome to P2P!
Old August 29th, 2006, 08:42 AM
Authorized User
Join Date: Aug 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts

No luck.....

Run-time error '3464':
Data Type Mismatch in criteria expression.
thank you for the welcome, not sure if this will help but here is the code that fills the Username box "txtNetUser"

Public Declare Function apiGetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long

Function fOSUserName() As String
On Error GoTo fOSUserName_Err

Dim lngLen As Long, lngX As Long
Dim strUserName As String

strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)

If lngX <> 0 Then
fOSUserName = Left$(strUserName, lngLen - 1)
fOSUserName = ""
End If

Exit Function

MsgBox Error$
Resume fOSUserName_Exit
End Function
Old August 29th, 2006, 09:05 AM
Authorized User
Join Date: Jul 2006
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts

Hi Devilboy13

Here is a code that I have use for a username & Password:
You will need to create a table with the following fields: UserName and Pass, will call this table tblUser. Then create a form with a username and password fields and add a submit and cancel button.

Let me know if you get stuck and I can send you some more instructions.


Private Sub CancelButton_Click()
DoCmd.RunCommand acCmdExit
End Sub

Private Sub okButton_Click()
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
 If IsNull(Me.UserTxt) Then
   MsgBox "Please enter a valid user name.", vbExclamation, "Error"
   Exit Sub
 ElseIf IsNull(Me.PassTxt) Then
   MsgBox "Please enter a valid password.", vbExclamation, "Error"
   Exit Sub
 End If
  rs.Open "SELECT * FROM tblUser WHERE(UserName = """ & Me.UserTxt & """ AND Pass = """ & Me.PassTxt & """)", _
   CurrentProject.Connection, adOpenKeyset, adLockOptimistic
    If rs.EOF Then
      MsgBox "Invalid user name or password. Please try again.", vbExclamation, "Error"
     Exit Sub
    End If
 MsgBox "Login Successful.", vbInformation, "Confirm!"
Exit Sub
End Sub

Old August 30th, 2006, 02:48 PM
Authorized User
Join Date: Aug 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks that worked... You are a life saver...

Similar Threads
Thread Thread Starter Forum Replies Last Post
dlookup problem alemok Access 0 April 17th, 2008 02:50 AM
Problem with Dlookup JAdkins Access VBA 1 January 11th, 2008 06:52 PM
Dlookup problems jik VB How-To 0 February 15th, 2007 04:27 PM
Dlookup and variables Jaqx Access 3 September 29th, 2006 06:47 AM
DLookup Teqlump Access VBA 1 August 9th, 2006 11:48 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.