"Browse" Button Needed

XANAX

New member
Local time
Today, 02:13
Joined
Jan 24, 2007
Messages
5
I have a form that has a "Browse" command button that does not work because I do not have a great deal of knowledge in VB. This "Browse" buttons function is only to open a dialog box that will show the drives on a machine/server and allow the user to select the path of where the image(s) resides. Then a link will be created in the table showing the ImageDestination. Does anyone have or know of any way that this can be accomplished?

TIA:eek:
 
Search this forum for the FileDialog object. I know I have posted at least one full example, and many others have offered similar approaches.

There is a lot of detail in this response from eight days ago.
 
"Browse" button for file location

Thank you Moniker for replying. I tried your recommendation and I did not get the results I was looking for. It also maybe that I did something wrong. I am including a screen snap shot of what I am trying to achieve to better help describe what I need in case I am doing a poor job in that. So if anyone can help I would greatly appreciate it.


TIA

:eek:
 

Attachments

  • Browse-Button-Needs.gif
    Browse-Button-Needs.gif
    73 KB · Views: 157
I provided exactly that. Take the code that is provided in the link in my previous post and place it in the "OnClick" Event of your "Browse" button (renaming the Sub to match the name of your button's name), and you'll get that exact browser window.
 
"BROWSE" Button Needed

Moniker thank you very much. That was exactly what I needed. I forgot to change the Sub to my BROWSE buttons name. Your AWESOME!!!!! :cool: Just one last question: How do I pass the value to the open text box next to the button? Sorry for the ignorance, but I am new to this.


TIA

:o
 
Last edited:
Pass the value of the open textbox? I'm not sure what you mean, but I think you may mean the file path/name. Just make strFilename a global variable (put Global strFilename As String at the very top of a module) and it will be available to all forms/modules. If I guessed wrong, explain a little more what you meant.
 
"BROWSE" Button Needed

Does that mean I have to create a module and just put that code in there and leave it at that or do I include it in the code that you gave me previously. I have attached an image to better describe what I am trying to achieve. Thank you for your time and knowledge.
 

Attachments

  • Browse-Button-Needs2.gif
    Browse-Button-Needs2.gif
    78.6 KB · Views: 126
Yes, make a new module (call it something obvious like modGlobal) and at the very top of it, put this:

Global strFileName as String

Now, the variable strFileName will be defined and accessible everywhere. This means, of course, that you need to remove the filename string definition from my previous example, like this:

Code:
Private Sub cmdSelectExcelFile_Click()

    Dim dlg As FileDialog
    [COLOR="Red"]'Removed Dim FileSelected as String[/COLOR]

    Set dlg = Application.FileDialog(msoFileDialogFilePicker)
    With dlg
        .Title = "Select the Excel file to import"
        .AllowMultiSelect = False
        .Filters.Clear
        .Filters.Add "Excel Files", "*.xls", 1
        .Filters.Add "All Files", "*.*", 2
        If .Show = -1 Then
            [COLOR="Red"]strFileName[/COLOR] = .SelectedItems(1)
        Else
            Exit Sub
        End If
    End With

End Sub

The variable strFileName can be used to assign it to your textbox.

YourTextboxName = strFileName
 
Moniker,

You are the best!!!!! :cool: Thank you so much for all your help. Everything works like a charm.

Now I am going to hit the book and see if I can find anything on validating a combo box, to make sure it was used.

Thanks Again,

XANAX :)
 
Hi, I used all the information in your previous messages to create a Browse button to select an Excel file to import into Access, & everything works. In the code how do I specify that I want the imported data to Automatically import into a certain table? Please let me know.
Thanks
 
DoCmd.TransferSpreadsheet acImport,acSpreadsheetTypeExcel8,Your_Table_Name_Here,Your_File_Name_Here
 
Am I able to use this code without putting the xl File name I need to import? I want to be able to have user browse through their directory & import their file directly to a specified table name. Please let me know & thank you very much for your help.
 
Using the previous code to get the File Name (strFileName), you can simply use that reference in there.
 
Hi, Thank you again fro your help. I am just not that good with this, this is what I put in & I get the dialog box & I choose the xl file, but then I get a Run-time error stating: The action or method requires a Table name argument. See code below:

Private Sub cmdSelectExcelFile_Click()

Dim dlg As FileDialog
'Removed Dim FileSelected as String

Set dlg = Application.FileDialog(msoFileDialogFilePicker)
With dlg
.Title = "Select the Excel file to import"
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "Excel Files", "*.xls", 1
.Filters.Add "All Files", "*.*", 2
If .Show = -1 Then
StrFileName = .SelectedItems(1)
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel8, T_name, StrFileName
Else
Exit Sub
End If
End With

End Sub
 
It's telling you that "T_name" is not a valid table name because it needs to be in quotes.

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel8, "T_name", StrFileName

It's expecting literals there. You can use a string variable (like you did for StrFileName) if you have a string setup as the table name. Otherwise, put the literal name of the table you want to import into in quotes.
 

Users who are viewing this thread

Back
Top Bottom