Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run query from button click

Status
Not open for further replies.

BrianLe

Programmer
Feb 19, 2002
229
0
0
US
In Access 97, I have frmAddNewTrainNo with lbxLastTrainNo that gets its data from tblTrainNoQuery. The form also has cbxTrainNo where new TrainNo's are added.

How do I re-run my query tblTrainNoQuery when the cmdAddRecord button is clicked so that lbxLastTrainNo will update with the just added TrainNo?

Here is code for the cmdAddRecord buttom.

Private Sub cmdAddRecord_Click()

On Error GoTo Err_cmdAddRecord_Click
DoCmd.GoToRecord , , acNewRec

Exit_cmdAddRecord_Click:
Exit Sub

Err_cmdAddRecord_Click:
MsgBox Err.Description
Resume Exit_cmdAddRecord_Click

End Sub

I have tried using frmAddNewTrainNo.Form.Requery and frmAddNewTrainNo.Refresh.

Thanks, Brian


 
Hey Brian,
Have you tried:
Docmd.OpenQuery "tblTrainNoQuery" on the click even of your button?
 
That works good to run and open the query, but I would like lbxLastTrainNo to show the result of the re-run.
 
I mean I would like lbxLastTrainNo to show the result of the re-run of the query right away after clicking the cmdAddRecord button, ie. without having to close and reopen frmAddNewTrainNo. Thanks, Brian
 
I found this to work in the code for frmAddNewTrainNo.

Private Sub Form_Current()
Me!lbxLastTrainNo.Requery
Me!cbxTrainNo.Requery
End Sub

Now when the new TrainNo is entered into cbxTrainNo, and cmdAddRecord is clicked, lbxLastTrainNo is updated and shows what was just entered. And, cbxTrainNo has also been updated with the latest TrainNo, so if another new TrainNo is entered into cbxTrainNo, cbxTrainNo is already pre-populated and the new TrainNo can be entered by editing it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top