Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    RonAbbott is offline Novice
    Windows 11 Access 2007
    Join Date
    Nov 2022
    Posts
    21

    Command line option /x

    I understand this option can run a macro, but since a macro is just some vba code, is there a way of supplying the vba code instead of a macro name ?


    I get an access database from a third party and want to automate a “file import macros” and “file import modules” without first installing a macro to run the file import functions.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    What do you mean by 'macro' - a .bat or .vbs executable? Why would this macro be VBA code?

    Supplying VBA code to what? Install a macro where?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,932
    I think what you are saying is you have 3rd party app which contains importing routines and you want to add those routines to another db?

    If so, depends on whether the 3rd party app is .accdb or .accde and whether those macro's/functions in the module are public or not.

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    You just use the RunCode option in the called macro to run your public function doing your imports. Alternatively you can create an AutoExec macro that evaluates to passed argument in the command line call and runs the appropriate VBA code (this from MS site - replace the OpenForm with your import function calls):

    Code:
    Public Sub CheckCommandLine()
    
    
        ' Check the value returned by Command function and display
        ' the appropriate form.
        If Command = "Orders" Then
            DoCmd.OpenForm "Orders"
        ElseIf Command = "Employees" Then
            DoCmd.OpenForm "Employees"
        Else
            Exit Sub
        End If
    
    
    End Sub
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    RonAbbott is offline Novice
    Windows 11 Access 2007
    Join Date
    Nov 2022
    Posts
    21
    To clarify:
    I regularly get a third party (password protected) access database with selected tables that I want to export to my access database (which has no password requirements).
    I know the user name and password of the third party database, but would prefer not to have to log in and export the tables.
    Instead the ideal would be to use a macro or VBA code to import the tables into my access database, but get "unauthorised" message when trying to import from the third party database.
    So my other option is to get some code into the third party database (via a /x switch that takes VBA code instead of a macro name) so that the exporting of the selected tables (maybe 20 tables?) can be done automatically.
    The only way I seem to be able to do this at present is to log in to the third party database and import a macro that has the export functions, and then to run that macro from within the third party database. Not ideal.

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Ron,
    You can open the third party db in VBA using DAO and supplying the password, have you tried it?
    https://stackoverflow.com/questions/...has-a-password
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  7. #7
    RonAbbott is offline Novice
    Windows 11 Access 2007
    Join Date
    Nov 2022
    Posts
    21
    Quote Originally Posted by Gicu View Post
    Ron,
    You can open the third party db in VBA using DAO and supplying the password, have you tried it?
    https://stackoverflow.com/questions/...has-a-password
    Cheers,
    Thanks - that's helpful, though am using Access 2007 and I didnt think you could import from an open database (?)

    The next answer in that link might also help me - as the data from the third party will end up in a Microsoft SQL table.
    So rather than first getting the tables out of the third party database into my access database and then upload them to SQL, I'll try transferring the third party tables directly into the SQL tables via DAO

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Post 7 was moderated, I'm posting to trigger email notifications.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,932
    If you have linked tables to your sql db if transferdatabase doesn’t work you can just use a query

  10. #10
    RonAbbott is offline Novice
    Windows 11 Access 2007
    Join Date
    Nov 2022
    Posts
    21
    OK, I used the following code but still not working - is there a way to specify the user name as well as the password ?
    'Const
    dbImport = Forms!Main!CPath & "\RhmDat.mdb"
    'Const
    sPassword = "abc123"


    Dim DB As DAO.Database
    Set DB = DBEngine.OpenDatabase(Name:=dbImport, Options:=False, ReadOnly:=False, Connect:=";PWD=" & sPassword)
    DoCmd.TransferDatabase acImport, "Microsoft Access", dbImport, acTable, dbTable, dbTable, False
    DB.Close
    Set DB = Nothing

  11. #11
    RonAbbott is offline Novice
    Windows 11 Access 2007
    Join Date
    Nov 2022
    Posts
    21

  12. #12
    RonAbbott is offline Novice
    Windows 11 Access 2007
    Join Date
    Nov 2022
    Posts
    21
    "You do not have the necessary permissions to use the '......mdb' object. Have your system adminstrator establish the appropriate permissions for you"
    Also I am using Access 2003

  13. #13
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    It seems like the file is protected with the old mdw (workgroup) security, do you know if that is the case or is it just a database password?

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  14. #14
    RonAbbott is offline Novice
    Windows 11 Access 2007
    Join Date
    Nov 2022
    Posts
    21
    Yes, it has an mdw and user and group security settings - there seems to be no database password

  15. #15
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Can you remove the (now deprecated) ULS from the original file? The DAO example you are trying to use was intended for the databases protected with a database password, not ULS.

    https://support.microsoft.com/en-us/...rs=en-us&ad=us

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Command Line through Access
    By Forbes in forum Import/Export Data
    Replies: 6
    Last Post: 04-14-2017, 03:20 PM
  2. Command line to update records
    By Richard B in forum Programming
    Replies: 3
    Last Post: 10-01-2013, 06:03 AM
  3. calling mdb from command line.
    By gsd in forum Access
    Replies: 4
    Last Post: 05-04-2012, 08:17 PM
  4. VBA and command line
    By dsk96m in forum Access
    Replies: 1
    Last Post: 09-04-2011, 08:06 PM
  5. Pass command line parameters
    By lanto3000 in forum Access
    Replies: 2
    Last Post: 03-21-2010, 03:53 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums