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.
The bit I need to change is highlighted in red (I believe this is all).Code:Forms("frmIndex").IndexFrame.SourceObject = "frmMenu"
When I use a correct username and password and click logon to run the logon procedure (below) I recieve this error:
Please help me change the bits in red so it works. ThanksCode:Run-time error '2465' Microsoft Access cannot find the field 'frmLogon' referred to in your expression
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





Reply With Quote