How to automatically run query when data entry completed on form

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

Guest

I'm doing data entry on a form and have 10 fields. I want to automatically
run an update query after I enter the last field on the form. The udpate
query simply takes 3 of the fields just entered and combines into a lookup
key. How can I do this?
 
You could use the AfterUpdate event of your last field to trigger that code.

hth
Al Camp
 
Bruce,

I suggest using the form's BeforeUpdate event. You can thus perform
error-checking to make sure the three fields have valid data, and cancelling
if necessary:

Dim ctl As Control
For Each ctl in Me.Controls
' Add other control types to the criteria if they are present on your
form
If (ctl = acTextbox or ctl = acComboBox or ctl = acCheckbox) Then
Select Case ctl.Name
Case Field1:
' Place field-specific error-checking here
' If error condition found
Cancel = True
Msgbox ctl.Name & " does not have valid data. Please
reenter."
ctl.Setfocus
Case Field2:
etc.
End Select
Next ctl
If Cancel = False Then
DoCmd.OpenQuery "YourQueryName,,acAdd
End If

Hope that helps.
Sprinks
 
Back
Top