I have two tables (Company and Orders) that are linked 1-many. On the data entry form, there is a Continue button that when clicked grabs the contact information from the most recent order by the company selected from a combo box and re-queries the form's record source (q_Contacts) with this new record. The associated textboxes are then filled with the most recent contact information (Contact info is in Orders table and company name in Company table.)
I have several textboxes on the form that I want to populate with the contact information as in most cases this will information not change thus speeding up the tedium of data entry. Right now I am setting the form‘s record source to the query “q_Contacts” but this isn’t really what I want to do. I do not want the textboxes bound to the data in the Order table; just populated with it as the information on this form will be a new record. (Plus due to its 1-many relationship, I can't edit the textboxes anyway with the query.)
How do I query the tables and use the results of the query to populate the textboxes which need to be unbound? (They must remain unbound for reasons determined by powers that be higher in rank than me. It has to do with future plans for this database.")
My q_Contacts SQL:
Code:
SELECT Company.UID, Company.CompanyName, Orders.ContactLast, Orders.ContactFirst, Orders.ContactTitle, Orders.MailAdd, Orders.MailCity, Orders.MailState, Orders.MailZip, Orders.ContactPhone
FROM Company INNER JOIN Orders ON Company.UID = Orders.UID
GROUP BY Company.UID, Company.CompanyName, Orders.ContactLast, Orders.ContactFirst, Orders.ContactTitle, Orders.MailAdd, Orders.MailCity, Orders.MailState, Orders.MailZip, Orders.ContactPhone
HAVING (((Company.UID)=GetCompanyUID()));
I also have a module with the following code to grab the Company name value that was selected from the pull down menu before clicking “Continue”
Code:
Public varCompanyID As Long
Public Function GetCompanyUID() As Long
GetCompanyUID = varCompanyID
End Function
Coding for Continue button:
Code:
Private Sub cmdContinue_Click()
varCompanyID = cboCompanyName.Column(0)
Me.Requery ‘ Because the form’s recordsource is equal to the q_Contact query. Not what I want.
End Sub
Suggestions as to how to approach this?