Display results in the same form

D

dpac

Hi! The project im currently workin on requires me to perform a searc
to access records from a database in access. There are 5 cities t
search from but every search is done independantly from each city an
the results have to be displayed in the same form. Each city has aroun
10 fields.
I have a seperate query for each city. Each of these cities ar
selected accordingly from a combo box and its database is searche
using a common search button. I wrote a VB code to access each of thes
queries when selected from the combo box.
What im required to do is
1) display the results in the same form(but this only displays 5 out o
the 10 fields.)
2) Click on records to display another form with the rest of th
fields.

Please help me out on how to go about i
 
J

John Vinson

I have a seperate query for each city. Each of these cities are
selected accordingly from a combo box and its database is searched
using a common search button. I wrote a VB code to access each of these
queries when selected from the combo box.

I think the trick is to use *one* Paramter query, with a criterion

=[Forms]![YourFormName]![ComboboxName]

rather than five separate queries. You can then simply requery the
Form after selecting a row in the combo box, using the combo's
afterupdate event.

John W. Vinson[MVP]
 
D

dpac

Right! but i cant use one query because every city has different fields
For example
City 1 has 6 fields
City 2 has 11 fields
hence i had to query each city seperately. But that part is done, all
need to do rite now is display the results in the same form and don
know how to go about it. so plz help me out on tht account
 
J

John Vinson

Right! but i cant use one query because every city has different fields.
For example
City 1 has 6 fields
City 2 has 11 fields

That's VERY strange... but ok...
hence i had to query each city seperately. But that part is done, all i
need to do rite now is display the results in the same form and dont
know how to go about it. so plz help me out on tht account.

I'd suggest using a Subform control; you'll need five different forms,
one for each city. Have a Combo on the mainform to select the city,
and in its AfterUpdate event change the SourceObject property of the
subform.

John W. Vinson[MVP]
 
D

dpac

thankx!! I already have a combo box in the main form to access th
cities exclusively. As u suggested, I created 5 different subforms t
display results of each city too. Could u plz tell me in detail how t
go about changing the Sourceobject in the AfterUpdate event. Will thi
change, display only the subform that is accessed. Bcoz i dun want th
other subforms to b displayed when not accessed.

thankx again
dpa
 
D

dpac

thankx!! I already have a combo box in the main form to access th
cities exclusively. As u suggested, I created 5 different subforms t
display results of each city too. Could u plz tell me in detail how t
go about changing the Sourceobject in the AfterUpdate event. Will thi
change, display only the subform that is accessed. Bcoz i dun want th
other subforms to b displayed when not accessed.

I tried this code but i doesnt work

Private Sub Command11_Click() (Command11 is the search button)
On Error GoTo Err_Command11_Click

If Combo109 = "ALAMEDA" Then
Me![Alameda].Requery
ElseIf Combo109 = "HAWTHORNE" Then
Me![Hawthorne].Requery
ElseIf Combo109 = "MARTINEZ" Then
Me![Martinez].Requery
ElseIf Combo109 = "NAPA" Then
Me![Napa].Requery
ElseIf Combo109 = "SUSANVILLE" Then
Me![Susanville].Requery
ElseIf Combo109 = "NATIONAL CITY" Then
MsgBox "City Temporarily Unavailable", vbOKOnly
Else
DoCmd.ShowAllRecords
End If
Exit_Command11_Click:
Exit Sub

Err_Command11_Click:
MsgBox Err.Description
Resume Exit_Command11_Click

End Sub

thankx again
dpa
 
Top