Results 1 to 11 of 11
  1. #1
    sstiebinger is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Mar 2015
    Posts
    105

    Button to open form to new form with pre-selected fields

    I'm new to access, so thank you for taking the time to read and answer.

    I've got a table for contacts including:
    ID
    FirstName
    LastName
    Etc.

    I've got a table for appointments including:
    ID
    Subject
    ContactID - 1 to many relationship to Contacts.ID
    Etc

    I have a form for viewing/editing contacts, and on that form I want a button to open a new form to Add an Appointment for the currently displayed contact; so the appointments form will open to a new record, but with ContactID already populated from the current form's ID field...

    I simply can't figure out how to do this... I've tried several things based on Google, but I end up with either a blank for with nothing selected for ContactID, or the form opens to an existing record, I simply can't get it to open to a new record for the ContactID


    I can post example DB if that helps.

    If I add the appointments form as a subform to contacts, it works as I want so it seems there should be a way to separate this...

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Along the lines of

    DoCmd.OpenForm "NewForm"
    Forms!NewForm.ContactID = Me.ContactID

    If appropriate, you could also make the default value property of the textbox on the new form refer to the first form.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    sstiebinger is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Mar 2015
    Posts
    105
    That took care of it... I was using some similar code from other google searches, but this one worked where those did not.
    Thank you for the prompt response!

  4. #4
    sstiebinger is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Mar 2015
    Posts
    105
    Actually, I spoke too soon.... While using this code, when there are no appointments in the appointments table, it opens a new appointment with the current user...
    However once an appointment is created, it then opens the EXISTING appointment and CHANGES the user for the existing appointment... this is not desired behavior.

  5. #5
    sstiebinger is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Mar 2015
    Posts
    105
    Sorry, changed the new form Data Entry property to Yes and that fixed it...
    Sorry, still learning Access.

  6. #6
    sstiebinger is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Mar 2015
    Posts
    105
    Hmm, that takes care of entering new details, but by setting the form to Data Entry the user can no longer review previous appointments tied to that customer...
    Is there a way to do this where it defaults to a new record, but allows viewing other records tied to the same contact? Or must I create a separate form for viewing vs entering?

  7. #7
    sstiebinger is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Mar 2015
    Posts
    105
    DoCmd.GoToRecord acDataForm, "frmAppointments", acNewRec

    This line opens the form at a new record without having the data entry set to yes, but how can I have the filter for that new form be set to whatever the ContactID is?

  8. #8
    sstiebinger is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Mar 2015
    Posts
    105
    Marking as solved since this is a new issue, opened a new thread.

  9. #9
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Sorry, missed the followup question. Would this have helped?

    BaldyWeb wherecondition
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    sstiebinger is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Mar 2015
    Posts
    105
    I actually did reference that, thanks!

  11. #11
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Glad you got it sorted out!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Continuous search form won't open selected record in view form.
    By IncidentalProgrammer in forum Programming
    Replies: 20
    Last Post: 03-24-2015, 02:53 PM
  2. Replies: 24
    Last Post: 04-01-2014, 09:15 AM
  3. Replies: 3
    Last Post: 03-19-2013, 04:09 AM
  4. Replies: 3
    Last Post: 12-25-2012, 12:43 AM
  5. Replies: 7
    Last Post: 05-01-2012, 11:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums