Alright, figured out a few things but still confused on others.
This is for a "simple" data entry form.
WHAT I WANT:
1. Open combo box (created on form, no lookups,etc on table) choose a contact name.
2. Upon choosing name, a second Text Box will automatically display the business that the contact is associated to. Text Box should not be editable.
The first combo box works I think. Problem is with second box (Text Box).
WHAT I HAVE TRIED SO FAR:
First box is a combo box that looks up ContactID but displays the available list of Contact Names. This was arranged via the Wizard. This control is bound to a field in the tblContacts and so that table gets updated.
IN an attempt to get the Text Box to display the the associated business I ran an event off of the first combo box. (Code shown below)
My two cents: I think it has something to do with the data type being returned by the SQL query being of the wrong sort. I tried to return the result into one element of a string array because the query would ordinarily return a table. In this case, the answer will always be a 1 row/1 column table. I get no errors running this code. It just does nothing. Interestingly, if I change the array type to Integer a "0" is printed in the Text Box instead of the usual nothing.
Tables are as follows:
tblBusinesses
BusinessID, BusinessName
tblContacts
ContactID, BusinessID, ContactName
Code:
Private Sub ContactID_AfterUpdate()
On Error Resume Next
Dim MyTest(0) As String
MyTest(0) = "SELECT BusinessName " & _
"FROM tblBusinesses INNER JOIN tblContacts" & _
"WHERE BusinessID IN " & _
"(SELECT BusinessID " & _
"FROM tblContacts " & _
"WHERE ContactID = '" & ContactID.Value & "');"
Text7.Value = MyTest(0)
End Sub