Macro Command Button

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

Guest

I have a macro that saves data to an excel file. When I run the macro "excel
database" it works great. It comes up with a box asking if I want to
overwrite the file and I say yes. However, when I add a command button to my
form to run the macro, it doesn't run. I'm assuming that it's because it's
not giving me the box asking me if I want to overwrite the existing file.
What line do I put in my macro to do that. Here's the current language

Private Sub Command104_Click()
On Error GoTo Err_Command104_Click

Dim stDocName As String

stDocName = "Excel Database"
DoCmd.RunMacro stDocName
DoCmd.Close

Exit_Command104_Click:
Exit Sub

Err_Command104_Click:
MsgBox Err.Description
Resume Exit_Command104_Click

End Sub

Thanks for any help you can give.
 
Scrap the macro, and do the whole thing in VBA.

To check whether a file exists (and delete it if it does) using VBA, try:

If Len(Dir(strFullPathToFile)) > 0 Then
Kill strFullPathToFile
End If
 
I'm not a programmer so I'm do VERY limited VBA. Can you give me help on
programming to scrap the macro. I don't mind doing and learning, but I'm not
sure where to start. Have you seen an example and tutortial that may help me
with this?
 
Access has the ability to convert macros to VBA code.

Select the macro in the database window and right-click. Select Save
As/Export from the context menu that appears, and choose Save as Visual
Basic Module.
 

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

Back
Top