Results 1 to 10 of 10
  1. #1
    Join Date
    Aug 2011
    Posts
    19

    Unanswered: Autocomplete form using previous form

    I am having problems with a database that uses a Logon form. The form has a username and password combo box. The Row Source is tblEmployees. On AfterUpdate the code checks if the password entered is correct. If so, it then opens frmIntervention. The row source in frmIntervention are various lkp tables and the control source is tblInterventions. There is a combo box in frmIntervention for the staff members name

    I want to be able to do the following:

    When a staff member Logson using their Username and the frmIntervention is opened it will automatically populate the combo box with the staff members name. I can do this succcesssfully when the two forms are attached to the same table (see code from a different database) but I don't know what to do if the two forms use different tables.

    Code:
    Private Sub CourseTitle_AfterUpdate()
    Dim cTitle As String
        cTitle = Me.CourseTitle.Column(0)
        DoCmd.OpenForm "frmCourseStudentRecord", acNormal, , _
        "strCourseTitle='" & cTitle & "'"
        DoCmd.Close acForm, Me.Name
    End Sub

  2. #2
    Join Date
    Mar 2009
    Location
    Dorset
    Posts
    119
    When using user logins like this I normally have a hidden control on the main form (that needs to stay open for this to work) and then poulate it when the user logs in.

    Then whenever I want to poulate another field on different forms and reports I can just look at the control on the main form. Something like this:

    Me!FieldName = Forms!MainFormName!HiddenControlName
    Regards
    JD

    Software-Matters

  3. #3
    Join Date
    Aug 2011
    Posts
    19

    Autocomplete

    I am a bit new to this and just learning by trial and error. I have attached the concerned .mdb with the logon form and the frmintervention. What I want to do is take the strStaffName from the frmLogon, and populate it into the frmintervention Staff Name combo box. How do I include your code into what I already have, which is included under the OnClick function of the Logon page.

    Thanks for your help with this.
    Attached Files Attached Files

  4. #4
    Join Date
    Mar 2009
    Location
    Dorset
    Posts
    119
    Sorry but the zip file won't open.
    Try renaming the extension to .zzz so instead of MyDatabase.mdb change it to MyDatabase.zzz and then upload it.
    Regards
    JD

    Software-Matters

  5. #5
    Join Date
    Aug 2011
    Posts
    19

    Autocomplete

    I hope this version works.
    Attached Files Attached Files

  6. #6
    Join Date
    Mar 2009
    Location
    Dorset
    Posts
    119
    My code won't work with what you've got as it needs a form to stay open.

    Replace the section in your code with this:

    Code:
    'Close logon form and open splash screen
            
            
            DoCmd.OpenForm "frmintervention"
            Forms!frmintervention!Pharmacist = Me!cboUsername
            DoCmd.Close acForm, "frmLogon", acSaveNo
    
            Else
            MsgBox "Password Invalid.  Please Try Again", vbOKOnly, "Invalid Entry!"
            Me.txtPassword.SetFocus
        End If
    NB: On the version you sent me the staff box on the main form wasn't working so make sure it is set up as per the logon screen for the code to work.
    Regards
    JD

    Software-Matters

  7. #7
    Join Date
    Aug 2011
    Posts
    19

    Thumbs up Autocomplete

    Thanks for all the help. I think It is almost there. I have copied the code in and it almost works. In the main form it populates the staff name with the unique number from the lngMyEmpID rather than the StaffName. How do I tweak it so it puts the name in rather than the unique identifier?

  8. #8
    Join Date
    Aug 2011
    Posts
    19

    Autocomplete

    I have solved one problem, but I want it to go straight from the logon screen to a new record simply with the name populated for ease. I have attached what I have. You can see it populates the name but it goes to the first record rather than create a new record each time they logon.

    Help!
    Attached Files Attached Files

  9. #9
    Join Date
    Mar 2009
    Location
    Dorset
    Posts
    119
    Add the following line of code:

    DoCmd.Close acForm, "frmLogon", acSaveNo
    DoCmd.GoToRecord , , acNewRec
    Regards
    JD

    Software-Matters

  10. #10
    Join Date
    Aug 2011
    Posts
    19

    Thumbs up Autocomplete

    This now works a treat. Thanks for all the help.

Posting Permissions

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