By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,847 Members | 2,285 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,847 IT Pros & Developers. It's quick & easy.

FileBrowser in form.

P: 23
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.


I tried with "Filedialog".

but still not work.

Any help will be greately appriciated.
Thank You So Much.
Mar 7 '12 #1
Share this Question
Share on Google+
10 Replies

P: 6
Expand|Select|Wrap|Line Numbers
  1. Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
  2.          "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
  4. Private Type OPENFILENAME
  5. ' File broswer
  6.          lStructSize As Long
  7.          hwndOwner As Long
  8.          hInstance As Long
  9.          lpstrFilter As String
  10.          lpstrCustomFilter As String
  11.          nMaxCustFilter As Long
  12.          nFilterIndex As Long
  13.          lpstrFile As String
  14.          nMaxFile As Long
  15.          lpstrFileTitle As String
  16.          nMaxFileTitle As Long
  17.          lpstrInitialDir As String
  18.          lpstrTitle As String
  19.          flags As Long
  20.          nFileOffset As Integer
  21.          nFileExtension As Integer
  22.          lpstrDefExt As String
  23.          lCustData As Long
  24.          lpfnHook As Long
  25.          lpTemplateName As String
  26.        End Type
Expand|Select|Wrap|Line Numbers
  1.  ' Make the call
  2.    Private Sub OpenImportFileDialog_Click()
  4.          Dim OpenFile As OPENFILENAME
  5.          Dim lReturn As Long
  6.          Dim sFilter As String
  7.          Dim chosenFile As String
  8.          Dim chosenFileName As String
  9.          Dim filelocString As String
  10.          Dim structurename As String
  11.          Dim tablename As String
  12.          filelocString = "Default path"
  13.          structurename = "Specefication if any import is being done"
  14.          tablename = "Table name"
  16.          OpenFile.lStructSize = Len(OpenFile)
  17.          sFilter = "Text Files (*.txt)" & Chr(0) & "*.txt" & Chr(0)
  18.          OpenFile.lpstrFilter = sFilter
  19.          OpenFile.nFilterIndex = 1
  20.          OpenFile.lpstrFile = String(257, 0)
  21.          OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
  22.          OpenFile.lpstrFileTitle = OpenFile.lpstrFile
  23.          OpenFile.nMaxFileTitle = OpenFile.nMaxFile
  24.          OpenFile.lpstrInitialDir = filelocString
  25.          OpenFile.lpstrTitle = "Use the Comdlg API not the OCX"
  26.          OpenFile.flags = 0
  27.          lReturn = GetOpenFileName(OpenFile)
  28.          If lReturn = 0 Then
  29.             MsgBox "Action Cancelled"
  30.          Else
  32.          'assign chosen file  and file path to variables
  34.             chosenFileName = OpenFile.lpstrFileTitle
  35.             chosenFile = OpenFile.lpstrFile
  37.             'calls function to see if file has already been imported
  38.             'If CheckforFile(chosenFileName) = "NotExists" Then
  39.          ' Action to perform           
  40.             MsgBox "Data Imported to SAT table successfully!", vbOKOnly
  41.             'Else
  42.             'MsgBox "Hello - I'm here This file already exists in the table.  Please select a different file"
  43.            'End If
  44.          End If
  45.        End Sub
Hope this might give some idea
Mar 7 '12 #2

P: 23
Sir, Thank U so much for so quick reply.
I need to read this code first,then i will further contact you.
Mar 7 '12 #3

P: 23
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/

Mar 7 '12 #4

Expert Mod 15k+
P: 31,489

P: 23
Thank You NeoPa.
Hope it will help in my project.
Mar 8 '12 #6

Expert Mod 15k+
P: 31,489
It should do Usha. That's what it's there for.
Mar 8 '12 #7

P: 23
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?
Mar 12 '12 #8

Expert Mod 15k+
P: 31,489
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).
Mar 12 '12 #9

P: 23
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.
Mar 13 '12 #10

Expert Mod 15k+
P: 31,489
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.Caption 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.
Mar 13 '12 #11

Post your reply

Sign in to post your reply or Sign up for a free account.