Consulting

Results 1 to 5 of 5

Thread: Solved: Run an access macro thru excel

  1. #1
    VBAX Tutor
    Joined
    Sep 2007
    Posts
    265
    Location

    Solved: Run an access macro thru excel

    Hi there,

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

    [VBA]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[/VBA]

    here is the connection code

    [VBA]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
    [/VBA]

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,445
    Location
    This is all you need

    [vba]

    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
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Tutor
    Joined
    Sep 2007
    Posts
    265
    Location
    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.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,445
    Location
    If they don't have Access, I suggest that you move the code into Excel and run it from there.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Tutor
    Joined
    Sep 2007
    Posts
    265
    Location
    find bob, will try on it.

    Thank you so much and have a nice day.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •