Browse button

NHC

New member
Local time
Yesterday, 21:34
Joined
Aug 23, 2006
Messages
9
Hello all:
I'm trying to create a browse button in MS Access. Here is the code I've used so far:

Private Sub ImgBrowse_Click()


Dim OFN As OPENFILENAME
On Error GoTo Err_cmdInsertPic_Click

' Set options for dialog box.
With OFN
.lpstrTitle = "Images"
If Not IsNull([ImageFullPath]) Then .lpstrFile = [ImageFullPath]
.flags = &H1804 ' OFN_FileMustExist + OFN_PathMustExist + OFN_HideReadOnly
.lpstrFilter = MakeFilterString("Image files (*.bmp;*.gif;*.jpg;*.wmf)", "*.bmp;*.gif;*.jpg;*.wmf", _
"All files (*.*)", "*.*")
End With

If OpenDialog(OFN) Then
[ImageFullPath] = OFN.lpstrFile
[ImagePicture].Picture = [ImageFullPath]
SysCmd acSysCmdSetStatus, "Afbeelding: '" & [ImageFullPath] & "'."
End If
Form.Refresh
Exit Sub
Err_cmdInsertPic_Click:
MsgBox Err.Description, vbExclamation
End Sub

and here is what is in my module:

Option Compare Database

Public Type OPENFILENAME
lpstrTitle As String
lpstrFile As String
flags As Long
lpstrFilter As String

End Type

When I attempt to compile it says Sub or function not defined and highlights MakeFilterString. Why is this and how can I fix it? An ideas? Thank you
 
This is what happens when you copy & paste part of someone else's code. You missed copying the actual MakeFilterString function, which you can add to your Module:
Code:
Public Function MakeFilterString(ParamArray varFilter() As Variant) As String

    Dim strFilter As Variant

    For Each strFilter In varFilter
        MakeFilterString = MakeFilterString & strFilter & vbNullChar
    Next strFilter

End Function
 
Awesome

Hey thanks a lot! That solved that problem. Now it highlights OpenDialog and gives the same message. (yes I did borrow this code, with permission from the author)

Thank again!
 

Users who are viewing this thread

Back
Top Bottom