Sergio
Sergio

Reputation: 109

Run a Macro in ACCESS

i have a question about access 2000 or 2003 , i need to make a macro that opens the form and automatically clicks a button that runs a query , how can i do this, may some example can help me to do this ? any suggestions ? my idea is to run something like this:

Sub Refreshfiledata()
m  = MsgBox("Are you sure you want to run this macro ?.", vbYesNo)
If m = 6 Then
Application.DisplayAlerts = False
    SendKeys "{Enter}"
     Application.DisplayAlerts = True
      MsgBox "Done"
  End If
 End Sub

Upvotes: 0

Views: 208

Answers (1)

Fionnuala
Fionnuala

Reputation: 91376

Sendkeys is almost never a solution to anything.

You could put something like this in a module:

Sub OpenAForm()
    DoCmd.OpenForm "Form1"
    Forms!Form1.cmdClick_Click
End Sub

Which would refer to this code on form1, note that the word Private that Access usually adds before Sub has been deleted:

Sub cmdClick_Click()
    ''For a query to display data
    DoCmd.OpenQuery "Query1"
    ''For a query to change data
    CurrentDB.Execute "Query1", dbFailOnError
End Sub

You would have to alter the code to suit your set-up.

Upvotes: 2

Related Questions