Results 1 to 5 of 5

Thread: [RESOLVED] [vBA][Access][Urgent :)] Login Code within frmLogon not working in subform

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    125

    Resolved [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:
    1. [Option Compare Database
    2.  
    3. Private Sub cmdLogon_Click()
    4.     ' Set up variables
    5.     Dim dbs As Database
    6.     Dim userstable As DAO.Recordset
    7.     Dim usersRank As DAO.Recordset
    8.     Dim logonusername
    9.     Dim logonpassword
    10.  
    11.     'get data from the logon form
    12. [COLOR="Red"]    logonusername = Trim(Forms!frmIndex!frmLogon.Form!txtusername)          'Refers to txtusername.text within frmLogon within subform/subreport control (name: IndexFrame) within frmIndex
    13.     logonpassword = Trim(Forms!frmIndex!frmLogon.Form!txtpassword)          'Refers to txtpassword.text within frmLogon within subform/subreport control (name: IndexFrame) within frmIndex[/COLOR]
    14.  
    15.     ' open database
    16.     Set db = CurrentDb()
    17.  
    18.     'open the table
    19.     Set userstable = db.OpenRecordset("tblUsers", dbOpenDynaset)
    20.  
    21.     'find the users name
    22.     userstable.FindFirst "username = '" & logonusername & "'"
    23.     If userstable.Fields("username") = logonusername Then
    24.         If userstable.Fields("password") = logonpassword Then
    25.             Forms("frmIndex").IndexFrame.SourceObject = "frmMenu"
    26.         Else
    27.             MsgBox "Incorrect Password"
    28.         End If
    29.     Else
    30.         MsgBox "Incorrect Username"
    31.     End If
    32. End Sub
    33. Private Sub Command11_Click()
    34.     Forms("frmIndex").IndexFrame.SourceObject = "frmMenu"
    35. End Sub
    Last edited by emdiesse; Feb 17th, 2006 at 05:44 PM.
    Emdiesse

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width