 |
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
|
|
|

August 24th, 2006, 01:59 PM
|
Authorized User
|
|
Join Date: Aug 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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"
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txtPassword.SetFocus
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
|

August 28th, 2006, 10:16 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
|
|
Try
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!
|

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)
Else
fOSUserName = ""
End If
fOSUserName_Exit:
Exit Function
fOSUserName_Err:
MsgBox Error$
Resume fOSUserName_Exit
End Function
|

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.
Cheers
Hennie
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"
Me.UserTxt.SetFocus
Exit Sub
ElseIf IsNull(Me.PassTxt) Then
MsgBox "Please enter a valid password.", vbExclamation, "Error"
Me.PassTxt.SetFocus
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"
Me.UserTxt.SetFocus
Exit Sub
End If
MsgBox "Login Successful.", vbInformation, "Confirm!"
DoCmd.Close
Exit Sub
End Sub
|

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...
|
|
 |