Run Macro command

G

Guest

How can I run a Macro clientspecific and not for all customers. Every
customer has a clientID and I would like to run the Macro seperately for each
client.
I have the following code now (which is running for all)

Private Sub Command28_Click()
On Error GoTo Err_Command28_Click

Dim stDocName AsString

stDocName = "offer"
DoCmd.RunMacro stDocName

Exit_Command28_Click:
Exit Sub

Err_Command28_Click:
MsgBox Err.Description
Resume Exit_Command28_Click

End Sub

Thanks
Klaus
 
G

Guest

Don't use a macro,

What this Macro Do?
Mybe we can help you replacing it with code, and then you will be able to
run it for each client.
 
G

Guest

You were correct. I replaced the Macro with a code. It's working, but, how
can I get the prompts out (you are adding 2rows....) when I run the code?

Here is the code:

Private Sub Command34_Click()
On Error GoTo Err_Command34_Click

Dim stDocName As String
Dim strWhere As String

stDocName = "offerappend"
DoCmd.OpenQuery stDocName, acNormal, acEdit
strWhere = "[clientID] = " & Me.[clientID]
DoCmd.OpenReport "offercemetery", acViewNormal, , strWhere
stDocName = "offerdelete"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Exit_Command34_Click:
Exit Sub

Err_Command34_Click:
MsgBox Err.Description
Resume Exit_Command34_Click

End Sub
 
G

Guest

Yes, use the SetWarnings


stDocName = "offerappend"
DoCmd.OpenQuery stDocName, acNormal, acEdit
strWhere = "[clientID] = " & Me.[clientID]
DoCmd.OpenReport "offercemetery", acViewNormal, , strWhere
stDocName = "offerdelete"
Docmd.SetWarnings False
DoCmd.OpenQuery stDocName, acNormal, acEdit
Docmd.SetWarnings True
--
Good Luck
BS"D


Amateur said:
You were correct. I replaced the Macro with a code. It's working, but, how
can I get the prompts out (you are adding 2rows....) when I run the code?

Here is the code:

Private Sub Command34_Click()
On Error GoTo Err_Command34_Click

Dim stDocName As String
Dim strWhere As String

stDocName = "offerappend"
DoCmd.OpenQuery stDocName, acNormal, acEdit
strWhere = "[clientID] = " & Me.[clientID]
DoCmd.OpenReport "offercemetery", acViewNormal, , strWhere
stDocName = "offerdelete"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Exit_Command34_Click:
Exit Sub

Err_Command34_Click:
MsgBox Err.Description
Resume Exit_Command34_Click

End Sub


Ofer Cohen said:
Don't use a macro,

What this Macro Do?
Mybe we can help you replacing it with code, and then you will be able to
run it for each client.
 
G

Guest

Sorry , I just noticed you have two queries

stDocName = "offerappend"
Docmd.SetWarnings False
DoCmd.OpenQuery stDocName, acNormal, acEdit
strWhere = "[clientID] = " & Me.[clientID]
DoCmd.OpenReport "offercemetery", acViewNormal, , strWhere
stDocName = "offerdelete"
DoCmd.OpenQuery stDocName, acNormal, acEdit
Docmd.SetWarnings True
--
Good Luck
BS"D


Amateur said:
You were correct. I replaced the Macro with a code. It's working, but, how
can I get the prompts out (you are adding 2rows....) when I run the code?

Here is the code:

Private Sub Command34_Click()
On Error GoTo Err_Command34_Click

Dim stDocName As String
Dim strWhere As String

stDocName = "offerappend"
DoCmd.OpenQuery stDocName, acNormal, acEdit
strWhere = "[clientID] = " & Me.[clientID]
DoCmd.OpenReport "offercemetery", acViewNormal, , strWhere
stDocName = "offerdelete"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Exit_Command34_Click:
Exit Sub

Err_Command34_Click:
MsgBox Err.Description
Resume Exit_Command34_Click

End Sub


Ofer Cohen said:
Don't use a macro,

What this Macro Do?
Mybe we can help you replacing it with code, and then you will be able to
run it for each client.
 
D

Douglas J. Steele

Two possibilities.

One is to use SetWarnings to turn the warnings on and off:

DoCmd.SetWarnings False
stDocName = "offerappend"
DoCmd.OpenQuery stDocName, acNormal, acEdit
strWhere = "[clientID] = " & Me.[clientID]
DoCmd.OpenReport "offercemetery", acViewNormal, , strWhere
stDocName = "offerdelete"
DoCmd.OpenQuery stDocName, acNormal, acEdit

DoCmd.SetWarnings True

Better in my opinion, though, is to use the Execute method of the QueryDef
object:

Private Sub Command34_Click()
On Error GoTo Err_Command34_Click

Dim stDocName As String
Dim strWhere As String

stDocName = "offerappend"
CurrentDb.QueryDefs(stDocName).Execute dbFailOnError
strWhere = "[clientID] = " & Me.[clientID]
DoCmd.OpenReport "offercemetery", acViewNormal, , strWhere
stDocName = "offerdelete"
CurrentDb.QueryDefs(stDocName).Execute dbFailOnError

Exit_Command34_Click:
Exit Sub

Err_Command34_Click:
MsgBox Err.Description
Resume Exit_Command34_Click

End Sub


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Amateur said:
You were correct. I replaced the Macro with a code. It's working, but, how
can I get the prompts out (you are adding 2rows....) when I run the code?

Here is the code:

Private Sub Command34_Click()
On Error GoTo Err_Command34_Click

Dim stDocName As String
Dim strWhere As String

stDocName = "offerappend"
DoCmd.OpenQuery stDocName, acNormal, acEdit
strWhere = "[clientID] = " & Me.[clientID]
DoCmd.OpenReport "offercemetery", acViewNormal, , strWhere
stDocName = "offerdelete"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Exit_Command34_Click:
Exit Sub

Err_Command34_Click:
MsgBox Err.Description
Resume Exit_Command34_Click

End Sub


Ofer Cohen said:
Don't use a macro,

What this Macro Do?
Mybe we can help you replacing it with code, and then you will be able to
run it for each client.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top