update current form with query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form with various text boxes displaying the data in each. The REGION
is selectable by the user. I set up a query That retieves data based on the
region selected. When the query runs it pulls the data I need and pops up a
table. I want the data it retrieved to update the form displayed and not pop
up a table.
Can you point me in the correct direction.
David Michigan
 
On after update event of the region, you can open a recordset that based on
the query you created, and then populate the values from the query to the
text boxes in the form

Dim MyDB as database
Dim MyRec as recordset

set MyDb=codedb()
Set MyRec = MyDB.openrecordset("QueryName")
If MyRec.eof then
msgbox "No Data"
Else
Me.TextField1 = MyRec!Field1NameInQuery
Me.TextField2 = MyRec!Field2NameInQuery
Me.TextField3 = MyRec!Field3NameInQuery
Me.TextField4 = MyRec!Field4NameInQuery
End If
=======================================
Now, if the Region selected from a combo there is another way.
To the RowSource Property of the combo you can add the query, linked by the
region, then add all the fields to the combo.
On the after update event of the combo you can wrte the code

Me.TextField1 = Me.ComboName.column(1)
Me.TextField2 = Me.ComboName.column(2)
Me.TextField3 = Me.ComboName.column(3)
Me.TextField4 = Me.ComboName.column(4)

The column numer starts with 0
==========================================
 
Back
Top