|
-
Feb 17th, 2006, 05:34 PM
#1
Thread Starter
Lively Member
[RESOLVED] [vBA][Access][Urgent :)] Login Code within frmLogon not working in subform
I have a form called frmIndex with a subform called IndexFrame. IndexFrames Source Object is frmLogon. The logon form contains the code below.
When the database is opened frmIndex will show and the user wishing to logon will have to enter his username and password in the textboxes provided
(txtUsername and txtPassword) Then click cmdLogon. This will run the logon code.
If the username and password are correct the subforms Source Object will change to frmMenu thus displaying the menu form within the subform. To do that
this bit of code was used.
Code:
Forms("frmIndex").IndexFrame.SourceObject = "frmMenu"
The bit I need to change is highlighted in red (I believe this is all).
When I use a correct username and password and click logon to run the logon procedure (below) I recieve this error:
Code:
Run-time error '2465'
Microsoft Access cannot find the field 'frmLogon' referred to in your expression
Please help me change the bits in red so it works. Thanks 
This is the code I used:
VB Code:
[Option Compare Database
Private Sub cmdLogon_Click()
' Set up variables
Dim dbs As Database
Dim userstable As DAO.Recordset
Dim usersRank As DAO.Recordset
Dim logonusername
Dim logonpassword
'get data from the logon form
[COLOR="Red"] logonusername = Trim(Forms!frmIndex!frmLogon.Form!txtusername) 'Refers to txtusername.text within frmLogon within subform/subreport control (name: IndexFrame) within frmIndex
logonpassword = Trim(Forms!frmIndex!frmLogon.Form!txtpassword) 'Refers to txtpassword.text within frmLogon within subform/subreport control (name: IndexFrame) within frmIndex[/COLOR]
' open database
Set db = CurrentDb()
'open the table
Set userstable = db.OpenRecordset("tblUsers", dbOpenDynaset)
'find the users name
userstable.FindFirst "username = '" & logonusername & "'"
If userstable.Fields("username") = logonusername Then
If userstable.Fields("password") = logonpassword Then
Forms("frmIndex").IndexFrame.SourceObject = "frmMenu"
Else
MsgBox "Incorrect Password"
End If
Else
MsgBox "Incorrect Username"
End If
End Sub
Private Sub Command11_Click()
Forms("frmIndex").IndexFrame.SourceObject = "frmMenu"
End Sub
Last edited by emdiesse; Feb 17th, 2006 at 05:44 PM.
Emdiesse
-
Feb 17th, 2006, 07:02 PM
#2
Re: [vBA][Access][Urgent :)] Login Code within frmLogon not working in subform
frmLogon is not a child object of frmIndex (even if you are showing it that way), so Forms!frmIndex!frmLogon is not valid.
You need to refer to the form directly, eg:
VB Code:
logonusername = Trim(Forms!frmLogon!txtusername)
-
Feb 18th, 2006, 10:34 AM
#3
Thread Starter
Lively Member
Re: [vBA][Access][Urgent :)] Login Code within frmLogon not working in subform
 Originally Posted by si_the_geek
frmLogon is not a child object of frmIndex (even if you are showing it that way), so Forms!frmIndex!frmLogon is not valid.
You need to refer to the form directly, eg:
VB Code:
logonusername = Trim(Forms!frmLogon!txtusername)
Thats how I origionally had it but it comes up with this error instead:
Code:
Run-time error '2450':
Microsoft Access cannot find the form 'frmLogon' referred to in a macro expression or visual basic code
-
Feb 18th, 2006, 10:39 AM
#4
Re: [vBA][Access][Urgent :)] Login Code within frmLogon not working in subform
Ok, how about this:
VB Code:
logonusername = Trim(Forms!frmIndex!IndexFrame!txtusername)
-
Feb 18th, 2006, 10:40 AM
#5
Thread Starter
Lively Member
Re: [vBA][Access][Urgent :)] Login Code within frmLogon not working in subform
Oh, got it!
[Highlight=VB]
logonusername = Trim(Forms!frmIndex!IndexFrame.Form!txtusername)
logonpassword = Trim(Forms!frmIndex!IndexFrame.Form!txtpassword)
[/code]
I replaced frmLogon with IndexFrame. That was meant to be SubFormControlName:
VB Code:
Forms!MainFormName!SubFormControlName.Form!ControlName
Thanks for all the help though
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|