PDA

View Full Version : Solved: Run an access macro thru excel



slamet Harto
05-17-2009, 10:05 PM
Hi there,

I want to call an access macro to vba excell, please advise me what I'm doing wrong

Sub RunAccessMacro()
Dim appAccess As Object

Call Connect
Set appAccess = CreateObject("Access.Application")

With appAccess
Application.DisplayAlerts = False
.Open
.DoCmd.RunMacro "Update_data"
'.Quit
End With
Set appAccess = Nothing
End Sub

here is the connection code

Public Function Connect()
On Error GoTo Salah
Set Cn = New ADODB.Connection

Koneksi = "Driver={Microsoft Access Driver (*.mdb)}; dbq=" & glob_sdbPath & _
";uid=admin; pwd=abcd"

Cn.Open Koneksi

Sheets("MainMenu").Range("B2").Value = ""

Exit Function

Salah:

MsgBox "Connection to Database is Failed ! " _
& Chr(13) _
& Chr(13) _
& Chr(13) _
& "Please Contact Your System Administrator", vbCritical, MySecMsg
Sheets("MainMenu").Range("B2").Value = "Connection is Failed.."
Sheets("MainMenu").LogOutBtn.Enabled = False
Sheets("MainMenu").LogInBtn.Enabled = False
Sheets("MainMenu").EntryBtn.Enabled = False
Sheets("MainMenu").UpdateBtn.Enabled = False
Sheets("MainMenu").SearchBtn.Enabled = False
Sheets("MainMenu").ChgPwdBtn.Enabled = False
Sheets("MainMenu").ApptBtn.Enabled = 0: Sheets("MainMenu").ChgPwdBtn.Enabled = 0
End
End Function

Bob Phillips
05-18-2009, 01:00 AM
This is all you need



Sub RunAccessMacro()
Dim appAccess As Object

Set appAccess = CreateObject("Access.Application")

With appAccess
Application.DisplayAlerts = False
.Opencurrentdatabase glob_sdbPath
.DoCmd.OpenModule "Module1"
.Run "Update_data"
'.Quit
End With
Set appAccess = Nothing
End Sub

slamet Harto
05-19-2009, 01:34 AM
Hi Bob

Thanks for reply.

We still need input database password and open MS Access.
My question is how to passing the password thru the code and don't open the Access application.
As somehow other user doesn't have/installed with MS Access.

Thanks for assistance.

Bob Phillips
05-19-2009, 02:27 AM
If they don't have Access, I suggest that you move the code into Excel and run it from there.

slamet Harto
05-19-2009, 03:23 AM
find bob, will try on it.

Thank you so much and have a nice day.