Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2012
    Posts
    4

    Unanswered: transferDatabase and File location using variable

    Hello,

    I have two buttons created 1 that imports the db's file name and location into a variable called: strInputFileName

    The "Select File" button code is as follows:

    Private Sub btn_SelectDailyLog_Click()
    On Error GoTo Err_btn_SelectDailyLog_Click
    Me.btnUpdate.Enabled = False
    Me.txt_ImportFileName = ""

    Dim strFilter As String
    Dim strInputFileName As String
    DoCmd.SetWarnings False

    strFilter = ahtAddFilterItem(strFilter, "Microsoft Access Files (*.mdb)", "*.*")
    strFilter = ahtAddFilterItem(strFilter, "all Files (*.*)", "*.*")

    strInputFileName = ahtCommonFileOpenSave( _
    Filter:=strFilter, _
    OpenFile:=True, _
    DialogTitle:="Select the a Daily Log file for import...", _
    Flags:=ahtOFN_HIDEREADONLY)

    If Len(strInputFileName) > 0 Then
    Me.txt_ImportFileName = strInputFileName
    Me.btn_ImportDailyFile.Enabled = True
    End If



    DoCmd.SetWarnings True
    Exit_btn_SelectDailyLog_Click:
    Exit Sub

    Err_btn_SelectDailyLog_Click:
    MsgBox Err.Description
    Resume Exit_btn_SelectDailyLog_Click

    So this works fine in what I want it to do (i have a module installed that makes this work)

    My issue is I want the file location and name that is now in the variable to be used in my TransferDatabase button click...and here is the code i have (that doesn't work....

    Private Sub btn_ImportDailyFile_Click()
    DoCmd.TransferDatabase acImport, "Microsoft Access", "strInputFileName
    ", acTable, "Eventlog", "Swipedata"
    End Sub

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    You don't want quotes around the variable. That makes it literal text instead of a variable.
    Paul

  3. #3
    Join Date
    Feb 2012
    Posts
    4
    yes...that was my 1st problem thanks....my second problem was i didn't have a public variable to return the loction and name back to...so i can call it again.

    thanks!

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so declare the variable containing the file name in the relevant code modules main section, ie NOT in a specific function or sub
    if you need it visible in other modules declare it as public

    eg
    Code:
    option compare database
    option explicit
    dim strFileName as string
    ...
    public function.......
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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