View Full Version : Help Me With Code Please!!


Ryanh63
06-11-2008, 10:15 AM
Hiya i need help!
I am a student doin A Level ICT and my Coursework invovles databases and i need to create modules.

I am trying to create a simple password system where it looks up a table of authorised passwords. I have one table named tblpassword and a form names frmopenpassword with a text box to enter the password and an accept commnad button to be pressed when the password has been entered. Here is the code i have but i keep getting an error about a missing operator or function.

Heres the code:

Private Sub Command2_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("Select * From TblPassword WHERE Password '" & Text0.Value & "'")
If rs.EOF Then
MsgBox ("Access Denied")

Else
Form_Switchboard.SetFocus
DoCard.Close acForm, "frmopenpassword"
End If
End Sub

Thank you

Ryan

pbaldy
06-11-2008, 10:37 AM
Where password...what?

WHERE Password = '"

ByteMyzer
06-11-2008, 10:38 AM
That should be:

Set rs = db.OpenRecordset("Select * From TblPassword WHERE Password = '" & Text0.Value & "'")

Ryanh63
06-11-2008, 01:12 PM
Ok i added that instead and that seems to cover that problem thanks; but as usual another crops up; it now says:

Error Message

"Microsoft Office Access can't find field 'i' refered to in your expression.

Thanks

Ryan

pbaldy
06-11-2008, 01:36 PM
On the recordset line? Hit Debug and see what value is returned when you hover over the form reference. Double check the spelling of all the names. Can you post a sample db?

Ryanh63
06-11-2008, 01:41 PM
Its ok now thanks for helping me you have been a great asset.

Iv done that the message box works correctly but after "Else" i then want to close the form; do you know what code i could possibly use please?

Thanks

Ryan

pbaldy
06-11-2008, 01:47 PM
You're on the right track, just misspelled

DoCmd.Close...

Ryanh63
06-12-2008, 07:37 AM
OK thanks that works

Ryan