+ Reply to Thread
Results 1 to 1 of 1

Macro retreiving data from SQL database through Access Linked tables and queries

Hybrid View

  1. #1
    Registered User
    Join Date
    02-12-2008
    Posts
    1

    Macro retreiving data from SQL database through Access Linked tables and queries

    Hi all,

    I'm new to this forum and I'm struggling with a problem in one of my Excel VBA macro's.

    I would like to retreive data from a MS access query, that on its turn is connected via ODBC to an SQL server.

    At this moment I'm able to get the data in my excel sheet via a macro, but each time I run the macro I need to enter the SQL database user profile and password, I would like to automate my macro in this way that I can put the profile and password within the macro.

    The code I'm using at thie moment looks like this:

    Sub importdatafromaccess()
    
    Static acc As Access.Application
    Dim strDbName As String
    
    strDbName = "L:\ELCBEBR\DEP-IT\Itrqst\ITR-2000-v2.mdb"
    
    Set acc = New Access.Application
    acc.Visible = True
    acc.OpenCurrentDatabase (strDbName)
    acc.DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "TZcopyleadtime", _
    "C:\Temp\TZcopyleadtime.xls", True
    acc.Quit
    Set acc = Nothing
    
    Workbooks.Open "C:\Temp\TZcopyleadtime.xls"
    Windows("Support Officer v-5.xls").Activate
    
    End Sub
    Could anyone help me automating this macro to put the profile and password coded into this script please.

    Thanks in advace,

    Frederik
    Last edited by VBA Noob; 02-12-2008 at 02:37 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1