SaladSnake
SaladSnake

Reputation: 167

Make 2 queries; one

Hello I'm a bit new to server commands so I was hoping anyone would give me a helping hand making this query.

I'm trying to insert data from 2 queries into a combo box but lack the knoledge to structure the query.

cmbGroups.RowSource = "Select GroupName, GroupNum from tblGroupHeader Where GroupName like '" & txtgroupSearch.Value & "*' or GroupNum like '" & txtgroupSearch.Value & "*';"
cmbGroups.Requery
cmbGroups.SetFocus
cmbGroups.Dropdown

cmbGroups.RowSource = "Select Alsoknown, GroupNum from tblAlsoKnown"

I'd also like the groupNum from AlsoKnown to go under the same column as the GroupNum from GroupHeader. Is this possible?

I was testing a few things out and I think i'm close to an answer New query:

Select tblGroupHeader.GroupName, tblGroupHeader.GroupNum, tblAlsoKnown.AlsoKnown from tblGroupHeader INNER JOIN tblAlsoKnown ON tblGroupHeader.GroupNum = tblAlsoKnown.GroupNum Where GroupName like '" & txtgroupSearch.Value & "*' or GroupNum like '" & txtgroupSearch.Value & "*';"

Upvotes: 1

Views: 48

Answers (1)

OpiesDad
OpiesDad

Reputation: 3435

Just do a join query as Marc B was implying:

cmbGroups.RowSource = "SELECT tblGroupHeader.GroupName" _
                           & ", tblGroupHeader.GroupNum" _
                           & ", tblAlsoKnown.AlsoKnown" _
                    & " FROM tblGroupHeader" _
                       & " LEFT JOIN tblAlsoKnown ON tblGroupHeader.GroupNum = tblAlsoKnown.GroupNum" _
                    & " WHERE tblGroupHeader.GroupName like '" & txtgroupSearch.Value & "*'" _
                          & " OR tblGroupHeader.GroupNum like '" & txtgroupSearch.Value & "*';"

cmbGroups.Requery
cmbGroups.SetFocus
cmbGroups.Dropdown

Upvotes: 1

Related Questions