473,581 Members | 3,234 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Photos in Access 2000

gm
Hi;
I have written a database that tracks all the installation we have ever
done. I have a small heating company.
I have recently started keeping a directory of digital photographs of the
completed job. I can create a hyperlink button that will link to a
photgraph, but I cannot link to a specific photo of that specific job. Each
job has its' own unique identifier, I call it the GOTC number. It is a
separate field in the table of installed equipment, and I display all of the
data in a form. In that form I created a command button called pic, but I
cannot find a way to dynamically point the hyperlink to the GOTC for that
job. I store the photos in a subdirectory of my database, because adding
them into the database would make it very unwieldy very quickly.
Is there a way to dynamically point to the picture in a given directory? It
would be even better if it will display several photos in that same
directory. Another choice might be to automatically open a windows explorer
with that directory (named as the GOTC number) with the display mode set to
thumbnails.

Please help me if you can.
TIA
Apr 14 '06 #1
1 3103
Ted
I use the following method of viewing images in an Access application:
On a form I insert an Image object from the forms toolbar.
Give it a name such as ImageSpot.
The table bound to the form should have field that is long enough to
hold the path and filename of the image which can be stored on the
local computer or a network server if you have one. Let's call that
ImagePath.
In the On Double-Click properties for that text box for that field I'll
add an Open File dialog that will retrieve the name of the image in a
common and easy to use interface and store the path and filename in the
ImagePath field. The same code will then issue a command to set the
image property of your ImageSpot object to the name of the image.

Here is the example of the Double-Click event:

Private Sub Image_DblClick( Cancel As Integer)
Dim strDirectory As String
Dim strTitle As String
Dim strSheetFilter As String

'Open the Open File dialog to retrieve the name of an image file
strDirectory = DLookup("[Data]", "tblAppSettings Local") &
"SubFolderName\ " 'Location of Images
strTitle = "Please select the desired Image"
strSheetFilter = "Image"

Me!ImagePath = TrimFilePath(Ge tOpenFile(strDi rectory, strTitle,
strSheetFilter) )

If IsNull(Me!Image Path) Or Me!ImagePath = "" Then
Me!ImageSpot.Pi cture = CurrentProject. Path & "\CompanyLogo.b mp"
Else
Me!ImageSpot.Pi cture = DLookup("[Images]",
"tblAppSettings Local") & "\" & Me!ImagePath
End If
End Sub

Once you have done that, then you need to be able to update the image
spot as you navigate through your records so I use this code in the
OnOpen AND the OnCurrent events for the form:

If IsNull(Me!Image Path) Or Me!ImagePath = "" Then
Me!ImageSpot.Pi cture = CurrentProject. Path & "\CompanyLogo.b mp"
Else
Me!ImageSpot.Pi cture = DLookup("[Images]",
"tblAppSettings Local") & "\" & Me!ImagePath
End If

You will note in the code above the statement:
strDirectory = DLookup("[Data]", "tblAppSettings Local") &
"SubFolderName\ " 'Location of Images
I use a table within the application where I store certain information
that may change but stays the same most of the time. These program
parameters can be easily maintained in one central location where many
different procedures can access the values, and if the value changes I
only have to change it in one location.

One other note of interest is that you can use the same
Me!ImageSpot.Pi cture = command to insert images into reports before
they print simply by adding the image hold to the detail section of the
report and adding the Me!ImageSpot.Pi cture = command to the OnFormat
event property of the Detail section of the report.

I got the following code from one of the Access web sites and modified
it just a little. Copy and paste it into a new module (I named my
module basOpenFileDial og). Then the code above will work to retrieve
the name of the image:

Option Compare Database

'************** *** Code Start **************
'This code was originally written by Ken Getz.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
' Code courtesy of:
' Microsoft Access 95 How-To
' Ken Getz and Paul Litwin
' Waite Group Press, 1996

Type tagOPENFILENAME
lStructSize As Long
hWndOwner As Long
hInstance As Long
strFilter As String
strCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
strFile As String
nMaxFile As Long
strFileTitle As String
nMaxFileTitle As Long
strInitialDir As String
strTitle As String
Flags As Long
nFileOffset As Integer
nFileExtension As Integer
strDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type

Declare Function aht_apiGetOpenF ileName Lib "comdlg32.d ll" _
Alias "GetOpenFileNam eA" (OFN As tagOPENFILENAME ) As Boolean

Declare Function aht_apiGetSaveF ileName Lib "comdlg32.d ll" _
Alias "GetSaveFileNam eA" (OFN As tagOPENFILENAME ) As Boolean
Declare Function CommDlgExtended Error Lib "comdlg32.d ll" () As Long

Global Const ahtOFN_READONLY = &H1
Global Const ahtOFN_OVERWRIT EPROMPT = &H2
Global Const ahtOFN_HIDEREAD ONLY = &H4
Global Const ahtOFN_NOCHANGE DIR = &H8
Global Const ahtOFN_SHOWHELP = &H10
' You won't use these.
'Global Const ahtOFN_ENABLEHO OK = &H20
'Global Const ahtOFN_ENABLETE MPLATE = &H40
'Global Const ahtOFN_ENABLETE MPLATEHANDLE = &H80
Global Const ahtOFN_NOVALIDA TE = &H100
Global Const ahtOFN_ALLOWMUL TISELECT = &H200
Global Const ahtOFN_EXTENSIO NDIFFERENT = &H400
Global Const ahtOFN_PATHMUST EXIST = &H800
Global Const ahtOFN_FILEMUST EXIST = &H1000
Global Const ahtOFN_CREATEPR OMPT = &H2000
Global Const ahtOFN_SHAREAWA RE = &H4000
Global Const ahtOFN_NOREADON LYRETURN = &H8000
Global Const ahtOFN_NOTESTFI LECREATE = &H10000
Global Const ahtOFN_NONETWOR KBUTTON = &H20000
Global Const ahtOFN_NOLONGNA MES = &H40000
' New for Windows 95
Global Const ahtOFN_EXPLORER = &H80000
Global Const ahtOFN_NODEREFE RENCELINKS = &H100000
Global Const ahtOFN_LONGNAME S = &H200000

Function TestIt()
Dim strFilter As String
Dim lngFlags As Long
strFilter = ahtAddFilterIte m(strFilter, "Access Files (*.mda,
*.mdb)", _
"*.MDA;*.MD B")
strFilter = ahtAddFilterIte m(strFilter, "dBASE Files (*.dbf)",
"*.DBF")
strFilter = ahtAddFilterIte m(strFilter, "Text Files (*.txt)",
"*.TXT")
strFilter = ahtAddFilterIte m(strFilter, "All Files (*.*)", "*.*")
MsgBox "You selected: " & ahtCommonFileOp enSave(InitialD ir:="C:\",
_
Filter:=strFilt er, FilterIndex:=3, Flags:=lngFlags , _
DialogTitle:="H ello! Open Me!")
' Since you passed in a variable for lngFlags,
' the function places the output flags value in the variable.
Debug.Print Hex(lngFlags)
End Function

Function GetOpenFile(Opt ional varDirectory As Variant, _
Optional varTitleForDial og As Variant, Optional strFilterZ As
String) As Variant
' Here's an example that gets an Access database name.
Dim strFilter As String
Dim lngFlags As Long
Dim varFileName As Variant
' Specify that the chosen file must already exist,
' don't change directories when you're done
' Also, don't bother displaying
' the read-only box. It'll only confuse people.
lngFlags = ahtOFN_FILEMUST EXIST Or _
ahtOFN_HIDEREAD ONLY Or ahtOFN_NOCHANGE DIR
If IsMissing(varDi rectory) Then
varDirectory = ""
End If
If IsMissing(varTi tleForDialog) Then
varTitleForDial og = ""
End If

' Define the filter string and allocate space in the "c"
' string Duplicate this line with changes as necessary for
' more file templates.

Select Case strFilterZ
Case "Spreadshee t"
strFilter = ahtAddFilterIte m(strFilter, _
"Spreadshee ts (*.xls), (*.wb3)", "*.XLS;*.WB 3")
Case "MDB"
strFilter = ahtAddFilterIte m(strFilter, _
"Access (*.mdb)", "*.MDB;*.MD A")
Case "Image"
strFilter = ahtAddFilterIte m(strFilter, _
"Images (*.bmp), (*.jpg)", "*.BMP;*.JP G")
Case Else
End Select

'If strFilterZ = "Spreadshee t" Then 'added this to filter for
spreadsheets
' strFilter = ahtAddFilterIte m(strFilter, _
' "Spreadshee ts (*.xls), (*.wb3)", "*.XLS;*.WB 3")
'Else
' 'not a spreadsheet
' strFilter = ahtAddFilterIte m(strFilter, _
' "Access (*.mdb)", "*.MDB;*.MD A")
'End If

' Now actually call to get the file name.
varFileName = ahtCommonFileOp enSave( _
OpenFile:=True, _
InitialDir:=var Directory, _
Filter:=strFilt er, _
Flags:=lngFlags , _
DialogTitle:=va rTitleForDialog )
If Not IsNull(varFileN ame) Then
varFileName = TrimNull(varFil eName)
End If
GetOpenFile = varFileName
End Function

Function ahtCommonFileOp enSave( _
Optional ByRef Flags As Variant, _
Optional ByVal InitialDir As Variant, _
Optional ByVal Filter As Variant, _
Optional ByVal FilterIndex As Variant, _
Optional ByVal DefaultExt As Variant, _
Optional ByVal FileName As Variant, _
Optional ByVal DialogTitle As Variant, _
Optional ByVal hWnd As Variant, _
Optional ByVal OpenFile As Variant) As Variant
' This is the entry point you'll use to call the common
' file open/save dialog. The parameters are listed
' below, and all are optional.
'
' In:
' Flags: one or more of the ahtOFN_* constants, OR'd together.
' InitialDir: the directory in which to first look
' Filter: a set of file filters, set up by calling
' AddFilterItem. See examples.
' FilterIndex: 1-based integer indicating which filter
' set to use, by default (1 if unspecified)
' DefaultExt: Extension to use if the user doesn't enter one.
' Only useful on file saves.
' FileName: Default value for the file name text box.
' DialogTitle: Title for the dialog.
' hWnd: parent window handle
' OpenFile: Boolean(True=Op en File/False=Save As)
' Out:
' Return Value: Either Null or the selected filename
Dim OFN As tagOPENFILENAME
Dim strFileName As String
Dim strFileTitle As String
Dim fResult As Boolean
' Give the dialog a caption title.
If IsMissing(Initi alDir) Then InitialDir = CurDir
If IsMissing(Filte r) Then Filter = ""
If IsMissing(Filte rIndex) Then FilterIndex = 1
If IsMissing(Flags ) Then Flags = 0&
If IsMissing(Defau ltExt) Then DefaultExt = ""
If IsMissing(FileN ame) Then FileName = ""
If IsMissing(Dialo gTitle) Then DialogTitle = ""
If IsMissing(hWnd) Then hWnd = Application.hWn dAccessApp
If IsMissing(OpenF ile) Then OpenFile = True
' Allocate string space for the returned strings.
strFileName = Left(FileName & String(256, 0), 256)
strFileTitle = String(256, 0)
' Set up the data structure before you call the function
With OFN
.lStructSize = Len(OFN)
.hWndOwner = hWnd
.strFilter = Filter
.nFilterIndex = FilterIndex
.strFile = strFileName
.nMaxFile = Len(strFileName )
.strFileTitle = strFileTitle
.nMaxFileTitle = Len(strFileTitl e)
.strTitle = DialogTitle
.Flags = Flags
.strDefExt = DefaultExt
.strInitialDir = InitialDir
' Didn't think most people would want to deal with
' these options.
.hInstance = 0
'.strCustomFilt er = ""
'.nMaxCustFilte r = 0
.lpfnHook = 0
'New for NT 4.0
.strCustomFilte r = String(255, 0)
.nMaxCustFilter = 255
End With
' This will pass the desired data structure to the
' Windows API, which will in turn it uses to display
' the Open/Save As Dialog.
If OpenFile Then
fResult = aht_apiGetOpenF ileName(OFN)
Else
fResult = aht_apiGetSaveF ileName(OFN)
End If

' The function call filled in the strFileTitle member
' of the structure. You'll have to write special code
' to retrieve that if you're interested.
If fResult Then
' You might care to check the Flags member of the
' structure to get information about the chosen file.
' In this example, if you bothered to pass in a
' value for Flags, we'll fill it in with the outgoing
' Flags value.
If Not IsMissing(Flags ) Then Flags = OFN.Flags
ahtCommonFileOp enSave = TrimNull(OFN.st rFile)
Else
ahtCommonFileOp enSave = vbNullString
End If
End Function

Function ahtAddFilterIte m(strFilter As String, _
strDescription As String, Optional varItem As Variant) As String
' Tack a new chunk onto the file filter.
' That is, take the old value, stick onto it the description,
' (like "Databases" ), a null character, the skeleton
' (like "*.mdb;*.md a") and a final null character.

If IsMissing(varIt em) Then varItem = "*.*"
ahtAddFilterIte m = strFilter & _
strDescription & vbNullChar & _
varItem & vbNullChar
End Function

Private Function TrimNull(ByVal strItem As String) As String
Dim intPos As Integer
intPos = InStr(strItem, vbNullChar)
If intPos > 0 Then
TrimNull = Left(strItem, intPos - 1)
Else
TrimNull = strItem
End If
End Function
'************** Code End *************** **

Function TrimFilePath(st rFile) As String
TrimFilePath = Right(strFile, (Len(strFile) - (InStrRev(strFi le,
"\"))))
'TrimFilePath = strFile
End Function

Apr 14 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
1733
by: Jeremy Simpson | last post by:
Can someone please help me with this? I am trying to put my jpg photos in my database. Access books seem to avoid the issue of graphics in DB tables and my searches on the internet seem to point me away from putting photos into tables (ultimately on forms). Has anyone successfully put viewable jpg's in their forms? Thanks Jeremy
1
1629
by: Chris Hartnell | last post by:
I have an Access 2003 database that has a text field which contains a path to a photo. Each new page of the report links to and displays the photo. I use the following code: Private Sub Report_Page() Dim sPath As String On Error GoTo ERR
3
2365
by: Dirk Goossens | last post by:
Hi! I stored the file name and path of photos in a table with data from students and teachers. Is there a way to show the photos in a report or form? Thanks! Dirk Goossens Vrij Instituut Sint-Lucas - Oudenaarde
2
2210
by: Ross | last post by:
Hi I have an application using asp.net that I am running on my PC. The web form has a text box where you can enter a name for a new Photo category then click on the button. The code is intended to create a new directory under Photos such as "Relatives".
4
2261
by: Dave G | last post by:
Firstly, apologies as this is not strictly an Access problem. I have a Access 2003 database containing records about people, and each person has 2 photos associated with the record. The photos are stored in a 'photos' folder. When a record is displayed, so are the photos. It all works fast and well. But I'm now getting close to 50,000...
2
2274
by: Frankie | last post by:
Using SQL Server 2005 and .NET 2.0; I'm creating a Windows Forms application that will need to display photos of people, along with a bunch of information about each person. In a Web application, there is a generally accepted "best practice" of storing only a string (the path to the .jpg file name), with the actual file stored in an NTFS...
2
3019
by: aaryan | last post by:
hi all, i just want to know how to store photos in sql server 2000 and to retrieve it thro' vb
10
2264
by: K. | last post by:
Hello all! I have a question to you. I would like to create photo gallery. I wonder if I should store photos (uploaded by users) in database $data = file_get_contents($_FILES); $data = mysql_real_escape_string($data);
4
3917
by: lorirobn | last post by:
Hi, I need to add photos to my database. Back End is on MS SQL Server (I believe 2000), and Front End is on MS Access. I have read about storing the photos as BLOBS, but I am not sure how to do this with SQL Server. Does this mean store the photo as OLE image, but do something else to it to make it a "Blob"? I have also read about...
0
7861
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8141
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8300
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7892
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5669
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5358
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3817
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2299
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.