Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do you create a browse button so the user can attach a file/image? 3

Status
Not open for further replies.

cutestuff

Technical User
Sep 7, 2006
162
CA
hi,

I have a data entry form where the user inputs information about a particular system. Sometimes though, these systems have images that need to be shown in the report.

I need to know if there is a way to create a "browse" button that the user can click and then search for a file to attach, then the path name of that file is stored in my table.

Please help.

Thank you so much...
 
Depending on your version of Access, you may be able to use:
Application.FileDialog
 
How are ya jenica024 . . .

You can also use the [blue]GetFilenameFromBrowse API[/blue].

Credit for the API goes to:
[blue]KPD-Team 2001[/blue]
URL:
I've modified the code slightly so it can be called from any form.

In a new module in the modules window copy/paste the following:
Code:
[blue]Private Const VER_PLATFORM_WIN32_NT = 2
Private Type OSVERSIONINFO
   dwOSVersionInfoSize As Long
   dwMajorVersion As Long
   dwMinorVersion As Long
   dwBuildNumber As Long
   dwPlatformId As Long
   szCSDVersion As String * 128
End Type

Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" _
                        (ByRef lpVersionInformation As OSVERSIONINFO) As Long
Private Declare Function GetFileNameFromBrowseW Lib "shell32" Alias "#63" _
                        (ByVal hwndOwner As Long, _
                         ByVal lpstrFile As Long, _
                         ByVal nMaxFile As Long, _
                         ByVal lpstrInitialDir As Long, _
                         ByVal lpstrDefExt As Long, _
                         ByVal lpstrFilter As Long, _
                         ByVal lpstrTitle As Long) As Long
Private Declare Function GetFileNameFromBrowseA Lib "shell32" Alias "#63" _
                        (ByVal hwndOwner As Long, _
                         ByVal lpstrFile As String, _
                         ByVal nMaxFile As Long, _
                         ByVal lpstrInitialDir As String, _
                         ByVal lpstrDefExt As String, _
                         ByVal lpstrFilter As String, _
                         ByVal lpstrTitle As String) As Long

Public Function BrowseFiles()
   Dim sSave As String
   
   sSave = Space(255)
   'If we're on WinNT, call the unicode version of the function
   If IsWinNT Then
      GetFileNameFromBrowseW Screen.ActiveForm.hwnd, _
                             StrPtr(sSave), _
                             255, _
                             StrPtr("c:\"), _
                             StrPtr("txt"), _
                             StrPtr("Text files (*.txt)" + Chr$(0) + "*.txt" + Chr$(0) + _
                                    "All files (*.*)" + Chr$(0) + "*.*" + Chr$(0)), _
                              StrPtr("The Title")
   'If we're not on WinNT, call the ANSI version of the function
   Else
      GetFileNameFromBrowseA Screen.ActiveForm.hwnd, _
                             sSave, _
                             255, _
                             "c:\", _
                             "txt", _
                             "All files (*.*)" + Chr$(0) + "*.*" + Chr$(0) + _
                             "Text files (*.txt)" + Chr$(0) + "*.txt" + Chr$(0), _
                             "The Title"
   End If
   
   BrowseFiles = Trim(Replace(sSave, Chr$(0), " "))

End Function

Public Function IsWinNT() As Boolean
   Dim myOS As OSVERSIONINFO
   
   myOS.dwOSVersionInfoSize = Len(myOS)
   GetVersionEx myOS
   IsWinNT = (myOS.dwPlatformId = VER_PLATFORM_WIN32_NT)

End Function[/blue]
Then from any form calls would look like:
Code:
[blue]   Me![purple][b][i]TextboxName[/i][/b][/purple] = BrowseFiles()
   [purple][b][i]variable[/i][/b][/purple] = BrowseFiles()[/blue]
[blue]Cheers! . . .[/blue]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top