Results 1 to 7 of 7
  1. #1
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2003
    Join Date
    Jun 2016
    Posts
    237

    passing a value from one form to another

    Hi,

    I have a combo box cboPublisher on a form frmBooks, with an event procedure for (On Not In List), if value entered is not in the list then a message box appears asking the user if he wants to add this value to the list with a vbYesNo + vbQuestion.
    If yes button is pressed, a form frmPublishers is oppened asking to add the new publisher to the table of publishers (tblPublishers). This form has two fields: publisher field (txtPublisher) and city field.
    How can I have the value the customer typed in the combo box (cboPublisher) to be copied to the publisher's field txtPublisherName in frmPublishers so that I do not need to type the value a second time.



    Khalil

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    use the full path names:
    forms!frmPublishers!txtPublisher = forms!frmBooks!cboPublisher


    (use the BUILDER, it always get the paths correct)


  3. #3
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    When they click Yes then a new record is added to the table and will be available to you in the combobox. Use this ID when opening the second form:
    DoCmd.OpenForm "formname",,[WHERE]"id=" & Me!combobox

  4. #4
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2003
    Join Date
    Jun 2016
    Posts
    237
    Hi,
    Thanks for the reply, still:
    This vba statement
    DoCmd.OpenForm "frmPublishers",,[WHERE]"pkPublisherId=" & Me.cboPublishes
    gave an error:
    expected end of statement and it highlighted the "pkPublisherId"

    any suggestions?

  5. #5
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    That [WHERE] I put in just to show you which parameter it was. When you type in VBA it tells you the order of the parameters. I couldn't remember how many commas were needed! Remove it.

  6. #6
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2003
    Join Date
    Jun 2016
    Posts
    237
    Hi,
    on the On Open Event for the frmPublisher I have the following line:
    DoCmd.OpenForm "frmPublishers", , "pkPublisherId=" & Me.txtPublisherName
    It clears the value in the combo box in the original form.
    Khalil

  7. #7
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    This is the place where this line would go (note the commas):
    DoCmd.OpenForm,,,"pkPublisherID=" & Me.txtPublisherName
    If yes button is pressed, a form frmPublishers is opened

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

Similar Threads

  1. Replies: 5
    Last Post: 11-18-2016, 10:27 AM
  2. Replies: 6
    Last Post: 07-16-2014, 12:18 PM
  3. passing value to new second form
    By englek in forum Forms
    Replies: 2
    Last Post: 08-08-2011, 01:40 PM
  4. passing variable from modal form to main form
    By crowegreg in forum Forms
    Replies: 2
    Last Post: 06-03-2011, 05:34 PM
  5. Passing value from one form to another
    By Molly152 in forum Forms
    Replies: 4
    Last Post: 11-16-2010, 11:03 AM

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