Opening a Form and Getting Value on A Click Event

C

Cliff

It has been a while since I done much Access VBA. I have a form
(frmInspectionDetail) to collect inspection data. On that form there is
a button that opens another form (frmPanel) that has several command
buttons that represent the items being inspected. I need to be able to
click on one of the items and have a variable associated with that item
(found in a table) passed back to the original calling form
(frmInspectionDetail), which will still be open.

I am not sure of the approach. In general I guess I need the command
button on the first form to launch some type of function that awaits
the value from the second form to be passed back so it can catch it.

Thanks for any ideas on how to do this?
 
K

Klatuu

There is a better way. Rather than opening a second form and passing data
back and forth, you could create a Combo Box control on your first form that
would give you a list of all the items being inspected. Then when you select
an item from that list, use the After Update event of the Combo Box to
retrieve the data from the table and put it in your text box. Here is an
example of how that could work. Of course you will have to change the code
to use your own names, etc:

Private Sub cboItemList_AfterUpdate()
Dim varItem as Variant

On Error GoTo cboItemList_AfterUpdate_Error

If Not IsNull(Me.cboItemList) Then
varItem = DLookup("[SomeField]", "SomeTable", "[Field to Match] = '" _
& Me.cboItemList & "'"
If IsNull(varItem) Then
MsgBox "Can't Find That Item"
Else
Me.SomeTextBox = varItem
End If
End If

cboItemList_AfterUpdate_Exit:
 
Top