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