Results 1 to 12 of 12
  1. #1
    Stephenson is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Location
    North West
    Posts
    110

    Using popup form to add entries into a subform


    Hello all,I'm trying to develop a form to display my vendors general information as well as a list of all of the contacts. I would like to use a popup form to add new contacts to the list of current contacts on my main form. I have a form, frmVendor, sfrmContact and frmContact. sfrmContact is a a continuous subform on frmVendor. On frmVendor I have command button, cmdAddContact that I would like to call my form, frmContact. I'm using the following code for this event.
    Code:
    Private Sub cmdAddContact_Click()        DoCmd.OpenForm "frmContact", , , "VendorID = " & Me!tboVendorID ,acFormAdd          Me.sfrmContact.RequeryEnd Sub
    My first problem is that this code does not open up fmrContact to the correct VendorID if I use acFormAdd. If I quote this out I am able to open to the correct ID, but on the current record and when I advance to a new record it goes to a new ID. Is there a way to open this form to the correct ID as well as a new record?My second problem is getting sfrmContact to show the new record once frmContact is closed. Is there a more effective way to do this beyond my current attempt? Thank you for having a look. I appreciate any feedback you may have. John

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    If the popup form will always be opened from the same form, you can make the default value property of the vendor refer to the form that opens it. If not, there are other ways around it.

    The requery should work, but the contact form would need to be opened in dialog mode so the requery doesn't happen until it closes. Or, do the requery from the close event of the popup form.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Stephenson is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Location
    North West
    Posts
    110
    Paul,

    Thank you for the quick response. My plan was to use the popup form in a similar fashion with another form. It would be easy however to make a copy of it and rename it however. I will play around with the default value, it never hurts to learn something new.

    I was intentionally keeping the requery event in the main form because I intend to use this form in conjunction with another form. I will make the popup open in dialog mode and see what happens.

    Could you point me in the direction of what to do if I don't keep the default value changed and use this form elsewhere as well?

    Thank you for your help,

    John

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can pass the value in OpenArgs and use that in the current event to set the value on the form, testing to make sure it's a new record:

    Code:
    If Me.NewRecord Then
      Me.TextboxName = Me.OpenArgs
    End If
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Stephenson is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Location
    North West
    Posts
    110
    Thank you for the idea.

    Here's what I'm working with now.


    Code:
    Private Sub cmdAddContact_Click()    DoCmd.OpenForm "frmContact", , , , acFormAdd, acDialog, tboVendorID.Value
        Me.sfrmContact.Requery
    End Sub
    And

    Code:
    Private Sub Form_Load(Cancel As Integer)    If Me.NewRecord Then
            Me.tboVenID = Me.OpenArgs
        End If
    End Sub
    I'm still not having any luck. The doesn't requery either.

    I'll keep trying.

    Thank you.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I mentioned the current event, though the load event might work for the first one. Can you attach the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Stephenson is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Location
    North West
    Posts
    110
    Here she is.

    I will try it on the current event. Honestly I didn't catch that at first.

    Thank you for the help.
    Attached Files Attached Files

  8. #8
    Stephenson is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Location
    North West
    Posts
    110
    Paul,

    I've only made a few tests, but it looks like your help got it up and working.

    I really appreciate your help once again.

    Have a great night,

    John

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Right off, there are all kinds of compile errors in this. Add this:

    http://www.baldyweb.com/OptionExplicit.htm

    to every module, then hit Debug/Compile and fix each error (until the compile doesn't return any errors).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Ah, I was typing and didn't see you got it working. I'd still fix those errors. For example this has 2:

    Code:
         If .CurrentRecord = 1 Then
            Form.cmdBack.Enabled = False
        DoCmd.GoToRecord , , acPrevious
    An If with no End If, and no With block defined.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    Stephenson is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Location
    North West
    Posts
    110
    I appreciate you looking Paul. I have set my DB to require variable deceleration. Looks like I have some debugging to do.

    Thanks again,

    John

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem John. Post back if there are any you can't figure 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. Replies: 14
    Last Post: 12-01-2015, 02:55 PM
  2. Replies: 10
    Last Post: 10-05-2015, 09:09 AM
  3. Replies: 1
    Last Post: 02-21-2013, 12:27 PM
  4. Replies: 1
    Last Post: 02-29-2012, 09:38 AM
  5. Form-Subform-Popup Problem
    By TrudyD1474 in forum Forms
    Replies: 1
    Last Post: 06-10-2010, 05:36 PM

Tags for this Thread

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