Reputation: 1
I want to refresh the Table in Access automatically every time after the Command Button is clicked. My code below works fine, but it will switch/open the Table. I would like to make it stay in the Form window only, not switch to the Table. Any idea is appreciated:
Private Sub Command0_Click()
''MsgBox Time
Dim db As Database
Set db = CurrentDb
currID = Time
n = "lala"
db.Execute "INSERT INTO Table1 ([Task],[From],[To]) VALUES ('" & n & "',#" & currID & "#,#" & currID & "#)", dbFailOnError
Set db = Nothing
DoCmd.SelectObject acTable, "Table1"
DoCmd.Requery
DoCmd.GoToRecord acDataTable, "Table1", acLast
End Sub
Upvotes: 0
Views: 6459
Reputation: 3031
Try Me.Recordset.Requery
this command does requery and keeps current record.
Upvotes: 0
Reputation: 1
Me.Requery
Me.Recordset.MoveFirst
worked for me as well and positioned the active record as I would generally prefer.
Upvotes: 0
Reputation: 3475
I assume that your form is also bound to Table1
.
So instead of
DoCmd.SelectObject acTable, "Table1"
DoCmd.Requery
DoCmd.GoToRecord acDataTable, "Table1", acLast
you can use
Me.Requery
Me.Recordset.MoveLast
Upvotes: 1