Results 1 to 6 of 6
  1. #1
    Giorgio is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2021
    Posts
    36

    Importing field content from one Form to another Form

    Hello everybody and thanks in advance for the help.
    We have a database of companies where we also store the history of contacts we had with them.
    Of course, there are companies with which we never had contacts so far, and others with whom we deal every day.
    So, when we have a contact with a new company, we have to insert the contact as a new one.

    The data are stored in two tables:
    TBLClients, where the basic contact info is stored. Fields are IDClient, CompanyName, CompanyAddress and many others.
    TBLContacts, where all the contacts are stored. Fields are only IDClient and Content
    IDClient of course link the two tables



    We use a form VisualizeClient (used to display ANY company, also the ones with no contacts, with the basic contact data from TBLClients) and in this form we have a button used to add a new contact; on click, it will open another input form InsertNewContact when we have a new contact with a client. This form of course opens showing empty fields. For companies with whom we already had contacts, there's a different button.

    We would need that when we click the button on VisualizeClient, while opening the form InsertNewContact, the value of the field of IDClient, coming from TBLClients, is directly imported in the form InsertNewContact and therefore in the TBLContacs

    So far, we are using this code:

    Code:
    Private Sub CMDInputNewContact_Click()
    On Error GoTo Err_CMDInputNewContact_Click
     
        Dim stDocName As String
        Dim stLinkCriteria As String
     
        stDocName = "FRMInsertNewContact"
       
        stLinkCriteria = "[TBLContacts.IDClient]=" & Me![TBLClients.IDClient]
       
        DoCmd.OpenForm stDocName, , , stLinkCriteria
     
    Exit_CMDInputNewContact_Click:
        Exit Sub
     
    Err_CMDInputNewContact_Click:
        MsgBox Err.Description
        Resume Exit_CMDInputNewContact_Click
       
    End Sub
    This opens the InsertNewContact form, but the field IDClient has to be filled by hand.
    We would need this field to be filled automatically using the data of IDClient in the VisualizeClient form.
    I hope it is clear

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    I tend to pass it in via OpenArgs and if a new record set the value in the Current event of the form.?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Giorgio is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2021
    Posts
    36
    Thanks for the reply, I never used OpenArgs, will try to find out how I can fit this in our code

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Or you could set the Default Value property of the IDClient textbox on the FRMInsertNewContact form to Forms!FRMVisualizeClient!IDClient (adjust to fit your form and control names).

    Cheers,
    Vlad
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    Giorgio is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2021
    Posts
    36
    Quote Originally Posted by Gicu View Post
    Or you could set the Default Value property of the IDClient textbox on the FRMInsertNewContact form to Forms!FRMVisualizeClient!IDClient (adjust to fit your form and control names).

    Cheers,
    Vlad
    You are a STAR! I was getting mad with the code, while that simple expression was the solution! Thanks a million!

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    You're welcome Giorgio! The main difference between the two solutions is that mine requires the calling form (VisualizeClient) to remain open while in the other it can be closed (as you already have passed the ID as the OpenArgs to the new form).

    Cheers,
    Vlad
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Replies: 12
    Last Post: 11-21-2019, 02:14 PM
  2. Replies: 17
    Last Post: 09-27-2019, 03:33 AM
  3. Replies: 7
    Last Post: 11-06-2017, 02:45 AM
  4. Replies: 2
    Last Post: 01-03-2015, 07:18 PM
  5. Replies: 4
    Last Post: 05-20-2014, 12:45 PM

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