Browse Button

peterbowles

Registered User.
Local time
Today, 16:07
Joined
Oct 11, 2002
Messages
163
Hi

I have a form which dispalys a student name and other details. I have a field in that form for a PATH name to a picture.

When I add a new student I want to be able to press a button and the file on my computer pops up and lets me choose the file and then inserts the path ino the correct field.(ImageField)

Any help would be great
 
Peter,

This is somewhat similar:

Put this code in a Public module and call it with: FileOpen

In this instance it puts the path AND Filename into a textbox
on the calling form.

' This is one line ...
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

Public Type OPENFILENAME
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

Public Sub FileOpen()
Dim OpenFile As OPENFILENAME
Dim lReturn As Long
Dim sFilter As String
Dim t As String
Dim i As Integer
Dim j As Integer

OpenFile.lStructSize = Len(OpenFile)
'OpenFile.hwndOwner = Form1.Hwnd
'OpenFile.hInstance = App.hInstance
sFilter = "Word Files (*.doc)" & Chr(0) & "*.doc" & 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 = "C:\"
OpenFile.lpstrTitle = "Use the Comdlg API not the OCX"
OpenFile.flags = 0
lReturn = GetOpenFileName(OpenFile)
For i = 1 To 20
t = Mid$(OpenFile.lpstrFile, i, 1)
j = Asc(t)
Next i
If lReturn = 0 Then
' This is where it puts the path and filename ...
Forms![ReadSubsystemDocument].[FileName] = ""
Else
OpenFile.lpstrFile = Mid$(OpenFile.lpstrFile, 1, InStr(1, OpenFile.lpstrFile, Chr(0)) - 1)
' This is where it puts the path and filename ...
Forms![ReadSubsystemDocument].[FileName] = Trim(OpenFile.lpstrFile)
End If

hth,
Wayne
 
Wayne...you're good...
 

Users who are viewing this thread

Back
Top Bottom