By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,466 Members | 1,599 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,466 IT Pros & Developers. It's quick & easy.

Need help

P: 47
hi
I am very very new to working in access and need some help. I have a table where a specific data is stored and i have a form where i added a text box. I want to check if the data entered in the text box is the same as the one in the table. Is there a specific code i need to use. Sorry if this seems pretty silly, but ive just started working.
Thanks
Mar 13 '08 #1
Share this Question
Share on Google+
6 Replies


MindBender77
100+
P: 234
hi
I am very very new to working in access and need some help. I have a table where a specific data is stored and i have a form where i added a text box. I want to check if the data entered in the text box is the same as the one in the table. Is there a specific code i need to use. Sorry if this seems pretty silly, but ive just started working.
Thanks
On the OnExit event of the textbox, you could use "DLookup" to find the record in the table. Example:
Expand|Select|Wrap|Line Numbers
  1. Dim data
  2.  
  3. data = dlookup("[Field Name]","YourTableName", "[Field Name] = Textbox")
  4.  
  5. If isnull(data) = true or data = "" then
  6. 'do something here
  7. Else
  8. Docmd.cancelevent
  9. End If
  10.  
Hope this Helps,
Bender
Mar 13 '08 #2

P: 47
On the OnExit event of the textbox, you could use "DLookup" to find the record in the table. Example:
Expand|Select|Wrap|Line Numbers
  1. Dim data
  2.  
  3. data = dlookup("[Field Name]","YourTableName", "[Field Name] = Textbox")
  4.  
  5. If isnull(data) = true or data = "" then
  6. 'do something here
  7. Else
  8. Docmd.cancelevent
  9. End If
  10.  
Hope this Helps,
Bender
Just let me know if the code i have written is right....
"New_password" is the field name
"Password" is the table name
"PswdTBox" is the name of the text box
Expand|Select|Wrap|Line Numbers
  1. If Data = DLookup("New_Password", "Password", "New_Password = PswdTBox") Then
  2.         DoCmd.OpenForm "Homepage", acNormal, , , acFormEdit, acWindowNormal
  3.         DoCmd.Close acForm, Me.Name
  4.     Else
  5.         MsgBox "Wrong Password! Sorry."
  6.     End If
Thanks
Mar 13 '08 #3

MindBender77
100+
P: 234
Just let me know if the code i have written is right....
"New_password" is the field name
"Password" is the table name
"PswdTBox" is the name of the text box

If Data = DLookup("New_Password", "Password", "New_Password = PswdTBox") Then
DoCmd.OpenForm "Homepage", acNormal, , , acFormEdit, acWindowNormal
DoCmd.Close acForm, Me.Name
Else
MsgBox "Wrong Password! Sorry."
End If


Thanks
Try:
Expand|Select|Wrap|Line Numbers
  1. Dim data 'This has to stay.
  2. data = DLookup("[New_Password]", "Password", "[New_Password] = PswdTBox") 
  3.  
  4. if isnull(data) = true or data = "" then
  5.          DoCmd.OpenForm "Homepage", acNormal, , , acFormEdit, acWindowNormal
  6.         DoCmd.Close acForm, Me.Name 
  7. else
  8.          MsgBox "Wrong Password! Sorry."
  9.     End If
  10.  
Bender
Mar 13 '08 #4

P: 47
Try:
Expand|Select|Wrap|Line Numbers
  1. Dim data 'This has to stay.
  2. data = DLookup("[New_Password]", "Password", "[New_Password] = PswdTBox") 
  3.  
  4. if isnull(data) = true or data = "" then
  5.          DoCmd.OpenForm "Homepage", acNormal, , , acFormEdit, acWindowNormal
  6.         DoCmd.Close acForm, Me.Name 
  7. else
  8.          MsgBox "Wrong Password! Sorry."
  9.     End If
  10.  
Bender

Well it doesnt work ..... it directly jumps to the else command.... is there something that i have to change in the table. The table has only the new password.... no other data is there in the table.... i'm pretty stumped...
Mar 13 '08 #5

P: 47
Try:
Expand|Select|Wrap|Line Numbers
  1. Dim data 'This has to stay.
  2. data = DLookup("[New_Password]", "Password", "[New_Password] = PswdTBox") 
  3.  
  4. if isnull(data) = true or data = "" then
  5.          DoCmd.OpenForm "Homepage", acNormal, , , acFormEdit, acWindowNormal
  6.         DoCmd.Close acForm, Me.Name 
  7. else
  8.          MsgBox "Wrong Password! Sorry."
  9.     End If
  10.  
Bender

Hey this actually works..... if i change the code to
"If IsNull(data) = False Or data = "" Then"
Thanks a lot dude... probably couldnt have done this without ur help...
Mar 13 '08 #6

NeoPa
Expert Mod 15k+
P: 31,186
Try :
Expand|Select|Wrap|Line Numbers
  1. If IsNull(DLookup("[New_Password]", _
  2.                   "[Password]", _
  3.                   "[New_Password]='" & Me.PswdTBox & "'")) Then
  4.   MsgBox "Wrong Password! Sorry."
  5. Else
  6.   DoCmd.OpenForm "Homepage", acNormal, , , acFormEdit, acWindowNormal
  7.   DoCmd.Close acForm, Me.Name
  8. End If
Make sure when you're testing that you check it handles both successful AND unsuccessful password entry.
Mar 15 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.