Wherecondition (1 Viewer)

Neilster

Registered User.
Local time
Yesterday, 21:10
Joined
Jan 19, 2014
Messages
218
Hi Guys

I have created a button called 'Bank Details' when clicked it opens a small form asking you to enter a 'password'

Once this operation has been done and clicked the enter button I want FrmBankDetails to open to a specific record that relates to a record from FrmAdmin.

The textbox in FrmAdmin is called 'StudentName' and the cbobox in FrmBankDetails is called cboStudentName.

This just doesn't work and have tried various ways. I know it can be done using Macros because I've done it, I need it in VBA so that the 'password' works.

PLease help.:confused::confused::confused:

Private Sub Command7_Click()
Dim strPass As String

strPass = "password"
If Me.txtPassword.Value = strPass Then

UnProtected = True

DoCmd.OpenForm "FrmBankDetails", Wherecondition:=" [StudentName]=" & [cboStudentName] & ""

DoCmd.Close acForm, "FrmBankDetailsLogin", acSaveNo

Else
If MsgBox("You need to enter a valid password, try again?", vbYesNo) = vbNo Then

DoCmd.Close acForm, "FrmBankDetailsLogin", acSaveNo

Else

txtPassword.Value = ""
txtPassword.InputMask = "Password"

End If

End If

End Sub

:banghead::banghead::banghead::banghead:
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 21:10
Joined
Aug 30, 2003
Messages
36,125
Oh, and "cboStudentName" needs to be the name of a control on the form the code is in, not the form being opened.
 

Neilster

Registered User.
Local time
Yesterday, 21:10
Joined
Jan 19, 2014
Messages
218
Hi Paul

I just keep getting a runtime error 438 - object doesn't support of this property or method

I can't think what I'm doing

Regards
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 21:10
Joined
Aug 30, 2003
Messages
36,125
On what line?
 

Neilster

Registered User.
Local time
Yesterday, 21:10
Joined
Jan 19, 2014
Messages
218
On this line,

DoCmd.OpenForm "FrmBankDetails", , , "StudentName = " & Me.StudentName

Now I'm getting a syntax error (missing operation) in query expression
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 21:10
Joined
Aug 30, 2003
Messages
36,125
You haven't clarified the data type of StudentName. As I said, if it's text you require delimiters. I'm guessing the error also includes the text of the condition?
 

Neilster

Registered User.
Local time
Yesterday, 21:10
Joined
Jan 19, 2014
Messages
218
This now works..

DoCmd.OpenForm "FrmBankDetails", , ,"StudentName ='" & Me.StudentName & "'"

However it doesn't work with 'Text Password Login in VBA code' If I just create a normal command button and put the above line of code in it works just fine, example..

Private Sub Command7_Click()

DoCmd.OpenForm "FrmBankDetails", , ,"StudentName ='" & StudentName & "'"

End Sub

No problems, but it won't work with the password login VBA??????

Any thoughts?
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 21:10
Joined
Aug 30, 2003
Messages
36,125
What does "doesn't work" mean exactly?
 

Neilster

Registered User.
Local time
Yesterday, 21:10
Joined
Jan 19, 2014
Messages
218
Well when you hit the enter button after entering the password, it will bring up 'FrmBankDetails' which is great, however moving through records and then checking someone else's bank details the from pops up but always with the 1st record details.

The code is correct in effect, but its not relating to a specific record??? well it just sticks with the first one.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 21:10
Joined
Aug 30, 2003
Messages
36,125
You've specified a specific student; is there perhaps something else the wherecondition should be based on?
 

Neilster

Registered User.
Local time
Yesterday, 21:10
Joined
Jan 19, 2014
Messages
218
I've tried everything.

All I want to do is have click a button called bank details on the admin form and then a small form will appear asking for a password, then click the arrow button which then brings up the student bank details.

The admin form is related to TblAdmin and so is the bank details form, if I just create a click button on the admin form to open up the bank details using..

Private Sub Command7_Click()

DoCmd.OpenForm "FrmBankDetails", , ,"StudentName ='" & StudentName & "'"

End Sub

It works just fine, so i'm at a loss as to why the below code will not do the same?? any thoughts.

Private Sub BankDetailsButton_Click()

Dim strPass As String

strPass = "ecn1001"
If Me.txtPassword.Value = strPass Then

UnProtected = True


DoCmd.OpenForm "FrmBankDetails", , , "StudentName = '" & Me.StudentName & "'"


DoCmd.Close acForm, "FrmBankDetailsLogin"



Else
If MsgBox("You need to enter a valid password, try again?", vbYesNo) = vbNo Then

DoCmd.Close acForm, "FrmBankDetailsLogin"

Else

txtPassword.Value = ""
txtPassword.InputMask = "Password"

End If

End If
End Sub
 

Neilster

Registered User.
Local time
Yesterday, 21:10
Joined
Jan 19, 2014
Messages
218
I'm pretty sure its something to do with the Bank Details password form??
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 21:10
Joined
Aug 30, 2003
Messages
36,125
Can you post a sample of the db here?
 

Neilster

Registered User.
Local time
Yesterday, 21:10
Joined
Jan 19, 2014
Messages
218
Not really the client would be most un happy.

I think what it is, is that when you open a form from a form then the relationship works.

I don't think it likes the idea of opening a form to open another form to open a form.

I'm trying to think of VBA that would when you click on a button on the admin form it opens a password form, which then opens the bank details form which relates to the admin form.

this is the best I can offer I'm afraid
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 21:10
Joined
Aug 30, 2003
Messages
36,125
Understandable, though I don't need their info, just a representative sample that illustrates the problem. I often use a little password form like this:

http://www.baldyweb.com/WrappedForm.htm

In which case all the basic code would be in the first form. If you want your password form to open the bank details form, you could pass the wherecondition in OpenArgs.
 

Neilster

Registered User.
Local time
Yesterday, 21:10
Joined
Jan 19, 2014
Messages
218
What is the 'OpenArgs' option about?????, I will give the above a try first though.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 21:10
Joined
Aug 30, 2003
Messages
36,125
OpenArgs is an argument of OpenForm. It allows you to pass a value or values to a form being opened, to be used later within that form.
 

smig

Registered User.
Local time
Today, 07:10
Joined
Nov 25, 2009
Messages
2,209
I think it will work if you send the filter data as OpenArgs and requery the form based on this data me.OpenArgs
 

Neilster

Registered User.
Local time
Yesterday, 21:10
Joined
Jan 19, 2014
Messages
218
So guys, How would I approach the below VBA with OpenArgs theory?

Private Sub BankDetailsButton_Click()

Dim strPass As String

strPass = "password"
If Me.txtPassword.Value = strPass Then

UnProtected = True


DoCmd.OpenForm "FrmBankDetails", , , "StudentName = '" & Me.StudentName & "'"


DoCmd.Close acForm, "FrmBankDetailsLogin"



Else
If MsgBox("You need to enter a valid password, try again?", vbYesNo) = vbNo Then

DoCmd.Close acForm, "FrmBankDetailsLogin"

Else

txtPassword.Value = ""
txtPassword.InputMask = "Password"

End If

End If
End Sub
 

Users who are viewing this thread

Top Bottom