Adding pictures

knightjp

Registered User.
Local time
Today, 15:39
Joined
Aug 14, 2008
Messages
11
Hey guys,

Trying to make a database of our company staff. Is there a way that I can click a button like "add picture" on a form and it opens dialog box for me to select a picture file and then displays it in an image box in the form.

Please let me know
 
I would first look at attachments. In Access 2007 there is an option for this have a cllok at the contact management database sample. It has exactly this function.
 
I would first look at attachments. In Access 2007 there is an option for this have a cllok at the contact management database sample. It has exactly this function.

I was looking for something with Access 2003
 

Attachments

I managed to make a new database where the button works.
Since I'm very new to programming and coding, I managed to go through some online tutorials and create the database.
I put the following code in the properties of the button

Option Compare Database
Code:
Private Sub addphoto_Click()
Me!Photograph = LaunchCD(Me)
End Sub


And added the following module:
Code:
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

Private 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

Function LaunchCD(strform As Form) As String
Dim OpenFile As OPENFILENAME
Dim lReturn As Long
Dim sFilter As String
OpenFile.lStructSize = Len(OpenFile)
OpenFile.hwndOwner = strform.hwnd
sFilter = "All Files (*.*)" & Chr(0) & "*.*" & Chr(0) & _
"JPEG Files (*.JPG)" & Chr(0) & "*.JPG" & 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 = "Select a file using the Common Dialog DLL"
OpenFile.flags = 0
lReturn = GetOpenFileName(OpenFile)
If lReturn = 0 Then
MsgBox "A file was not selected!", vbInformation, _
"Select a file using the Common Dialog DLL"
Else
LaunchCD = Trim(Left(OpenFile.lpstrFile, InStr(1, OpenFile.lpstrFile, vbNullChar) - 1))
End If
End Function



The "Add Photo" button on the form opens the dialog box to select the file, but after I select the file, its not displayed in the photo field.

If there is someone who can help me, I would greatly appreciate it.
 
I made a dummy database with the same button and coding as I posted earlier. Perhaps this will help you guys figure out where I went wrong
 

Attachments

im having simillar problems to you - and i cant help thinking that the module is very long winded -- i wonder excactly how much of that is used in the procedure and if it warrants being in a module at all -- is it a case of not seeing the wood for the trees?
 

Users who are viewing this thread

Back
Top Bottom