FileBrowser in form.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • usha2
    New Member
    • Mar 2012
    • 23

    #1

    FileBrowser in form.

    Hellow,
    I am new to this websight.but i trust this after reading all question-answer sections.

    My question is :

    How can i add a file browser on my form?

    I am using Access2003/VBA for access.

    I want to merge a access file in my database by open the file using file browser.

    HOW CAN I?

    I tried with "Filedialog ".

    but still not work.

    Any help will be greately appriciated.
    Thank You So Much.
  • vvasude2
    New Member
    • Feb 2012
    • 6

    #2
    Code:
    Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
             "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
    
    Private Type OPENFILENAME
    ' File broswer
             lStructSize As Long
             hwndOwner As Long
             hInstance As Long
             lpstrFilter As String
             lpstrCustomFilter As String
             nMaxCustFilter As Long
             nFilterIndex As Long
             lpstrFile As String
             nMaxFile As Long
             lpstrFileTitle As String
             nMaxFileTitle As Long
             lpstrInitialDir As String
             lpstrTitle As String
             flags As Long
             nFileOffset As Integer
             nFileExtension As Integer
             lpstrDefExt As String
             lCustData As Long
             lpfnHook As Long
             lpTemplateName As String
           End Type
    Code:
     ' Make the call
       Private Sub OpenImportFileDialog_Click()
             
             Dim OpenFile As OPENFILENAME
             Dim lReturn As Long
             Dim sFilter As String
             Dim chosenFile As String
             Dim chosenFileName As String
             Dim filelocString As String
             Dim structurename As String
             Dim tablename As String
             filelocString = "Default path"
             structurename = "Specefication if any import is being done"
             tablename = "Table name"
             
             OpenFile.lStructSize = Len(OpenFile)
             sFilter = "Text Files (*.txt)" & Chr(0) & "*.txt" & Chr(0)
             OpenFile.lpstrFilter = sFilter
             OpenFile.nFilterIndex = 1
             OpenFile.lpstrFile = String(257, 0)
             OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
             OpenFile.lpstrFileTitle = OpenFile.lpstrFile
             OpenFile.nMaxFileTitle = OpenFile.nMaxFile
             OpenFile.lpstrInitialDir = filelocString
             OpenFile.lpstrTitle = "Use the Comdlg API not the OCX"
             OpenFile.flags = 0
             lReturn = GetOpenFileName(OpenFile)
             If lReturn = 0 Then
                MsgBox "Action Cancelled"
             Else
             
             'assign chosen file  and file path to variables
             
                chosenFileName = OpenFile.lpstrFileTitle
                chosenFile = OpenFile.lpstrFile
                
                'calls function to see if file has already been imported
                'If CheckforFile(chosenFileName) = "NotExists" Then
             ' Action to perform           
                MsgBox "Data Imported to SAT table successfully!", vbOKOnly
                'Else
                'MsgBox "Hello - I'm here This file already exists in the table.  Please select a different file"
               'End If
             End If
           End Sub
    Hope this might give some idea

    Comment

    • usha2
      New Member
      • Mar 2012
      • 23

      #3
      Sir, Thank U so much for so quick reply.
      I need to read this code first,then i will further contact you.
      Regards
      usha

      Comment

      • usha2
        New Member
        • Mar 2012
        • 23

        #4
        Can you please clear me,

        when i click command button,what happed with this code?
        What objects required on form and where i write code/

        Thanks

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32669

          #5
          This might help (Select a File or Folder using the FileDialog Object).

          Comment

          • usha2
            New Member
            • Mar 2012
            • 23

            #6
            Thank You NeoPa.
            Hope it will help in my project.

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32669

              #7
              It should do Usha. That's what it's there for.

              Comment

              • usha2
                New Member
                • Mar 2012
                • 23

                #8
                when i use this code ,by doubleclicking the form the current path of the database shows in labels.

                How can i choose file(.mdb/.xls) from file dialog box?

                Where can i modify the code?

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32669

                  #9
                  We now have a question that I don't need to delete. What a relief!

                  Unfortunately, though it's in the right format, it's not very clear. What code are you referring to? How have you implemented it? To help you we need this information. It would also be helpful if you explained what you've read and what you understand from it. The linked article explains everything you need to know. If there's something there you don't understand then tell us what that is and we can move forward from there.

                  Also unfortunately, I feel compelled to reset the Best Answer post. I'm sure the code can be made to work, but it's not an appropriate anwser for this question in Access (as it uses the Windows API to achieve something that is already available in Access, albeit not the core application).

                  Comment

                  • usha2
                    New Member
                    • Mar 2012
                    • 23

                    #10
                    As per Neopa For more clear,
                    In access i have created a form.3 cmdbutton and 2 labels with some text.
                    after following the link send by Neopa ,when i double click on form the path of current database is appear on two labels.
                    So how the cmdbutton will work.
                    and as i need to merge with existing table by choose a .mdb/.xls file from file browser how can i do,where i should write code,where the code need modification.

                    Yes the annswer given by Neopa is best becoz after a long time atleast i got some path on my form design.
                    Last edited by usha2; Mar 13 '12, 01:31 PM. Reason: Spelling mistake.

                    Comment

                    • NeoPa
                      Recognized Expert Moderator MVP
                      • Oct 2006
                      • 32669

                      #11
                      I can't tell you exactly what you need to do with the code, because I really only understand a small amount of what you're saying. However, I will try to explain in basic terms what you need to do to modify and use the form.
                      1. You may only want the Command Button for the file. I don't think having the folder one available is any benefit to you. It's there to illustrate the options available, not because it's required for the other to work.
                      2. You will probably need to add a Command Button on the form to do the work that is specific to you. The existing form is for illustration only and does nothing with the names of the files when found (other than displaying them in the label).
                      3. Your code can run and refer to Me.lblFolder.Ca ption as the name (Full path reference) of the file selected by the user.

                      There's really little more that I can say, although it should be more than enough.

                      Comment

                      Working...