Results 1 to 5 of 5

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

  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

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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:
    1. logonusername = Trim(Forms!frmLogon!txtusername)

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    125

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

    Quote 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:
    1. 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
    Emdiesse

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

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

    Ok, how about this:
    VB Code:
    1. logonusername = Trim(Forms!frmIndex!IndexFrame!txtusername)

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    125

    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:
    1. Forms!MainFormName!SubFormControlName.Form!ControlName


    Thanks for all the help though
    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