473,657 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

importing and saving an image

Hello,
I am trying to import an image file into a form. This would be a
persons picture saved in the same directory for every unique record.
I don't have any problems making an action button to open the
directory where the images are but I am having problems putting the
images in the form and also linking a field in a table to this image.
I would rather not have the images saved in access2000 but simple
linked to the file in the directory storing all images.
I have loked at some exaples on here but don't see anything that I can
use.
Thanking everyone in advance
steve
Nov 12 '05 #1
2 2108
Steve,

Use an Image Control from the toolbox and look at the Picture property of the
control.
--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdata sheet.com
www.pcdatasheet.com
"steve" <st************ *@yahoo.com> wrote in message
news:49******** *************** ***@posting.goo gle.com...
Hello,
I am trying to import an image file into a form. This would be a
persons picture saved in the same directory for every unique record.
I don't have any problems making an action button to open the
directory where the images are but I am having problems putting the
images in the form and also linking a field in a table to this image.
I would rather not have the images saved in access2000 but simple
linked to the file in the directory storing all images.
I have loked at some exaples on here but don't see anything that I can
use.
Thanking everyone in advance
steve

Nov 12 '05 #2
One other thing you might want to do is allow the user to browse for
the file, and then just grab the path to it and write it into your
table.

Modified... original code from:
http://www.mvps.org/access/api/api0001.htm

'MODULE code....

'************** *** 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) 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.
strFilter = ahtAddFilterIte m(strFilter, _
"Access (*.mdb)", "*.MDB;*.MD A")
' 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 *************** **

'FORM code...
Option Compare Database

Private Sub Command0_Click( )
'txtImagePath is a textbox on the form.

Me.txtImagePath = TestIt
End Sub

Function TestIt()
Dim strFilter As String
Dim lngFlags As Long
strFilter = ahtAddFilterIte m(strFilter, "JPG files (*.jpg)")
strFilter = ahtAddFilterIte m(strFilter, "Bitmap Files (*.bmp)",
"*.BMP")
strFilter = ahtAddFilterIte m(strFilter, "GIF Files (*.gif)",
"*.GIF")
strFilter = ahtAddFilterIte m(strFilter, "All Files (*.*)", "*.*")
TestIt = 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
'---END CODE------------

yes, sorry for posting lots of code that I didn't write... it's just
that I had to tweak it a little to get it to work the way he asked...

HTH,
Pieter
Nov 12 '05 #3

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

Similar topics

4
48212
by: Michael Kennedy [UB] | last post by:
Hi Everyone, I have this multithreaded C# windows forms application which does a lot of image processing. Occasionally, I get the following error: A generic error occurred in GDI+. System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+. at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
14
1882
by: MLH | last post by:
GHudson has working procedures posted at http://www.access-programmers.co.uk/forums/showthread.php?t=66320 They work. Relationships, however, and some minor default settings are not preserved. Reestablishing some default settings and settings is a small price to pay for a set of text files that may save your database from total loss #AND# seem to remove the database bloat as well. I was wondering if someone knew how to preserve the...
2
3762
by: Peder Y | last post by:
My code is something like this: --------------- Image img = Image.FromFile("somefile.bmp"); FileStream fStream = new FileStream("someBinaryFile.dat"); BinaryWriter bw = new BinaryWriter(fStream); img.Save(bw.BaseStream, ImageFormat.Bmp);
4
3287
by: dale zhang | last post by:
Hi, I am trying to save and read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp Right now, I saved images without any errors. After reading the ole object from db, I saved it to C: as file1.bmp and displayed on the web. But it can not be displayed. After I manually sent the file to wordpad, it shows
1
1992
by: M Keeton | last post by:
I currently have a picture which is stored in a "System.Drawing.Image" variable and I want to save it as a bitmap file. I have tried 2 different approaches and both give me the following error: An unhandled exception of type 'System.Runtime.InteropServices.ExternalException' occurred in system.drawing.dll Additional information: A generic error occurred in GDI+.
5
4729
by: TheGanjaMan | last post by:
Hi everyone, I'm trying to write up a simple image stamper application that stamps the Exif date information from the jpegs that I've taken from my digital camera and saves the new file with the date stamped on the lower right part of the picture. (I'm not an advanced programmer so my code may not be 100% efficient - sorry, I'm still learning) Everything works fine until the saving part. I've been able to read the file into a...
2
2511
by: Mark Denardo | last post by:
Hi, I need some expert GDI+ person to help me with my RoundOffImage Function: What I'm trying to do is take in an image, crop off the edges around an ellipse region I set up, and then return the cropped image from the function. I sort of have this working, but not thoroughly. If I take the output image of this function and draw it on my form it shows the clipped image as transparent as I am wanting it. But if I take that image and...
6
6446
by: Mark Denardo | last post by:
My question is similar to one someone posted a few months back, but I don't see any replies. Basically I want to be able to have users upload photos and save them in a database (as byte data) and be able to load them to an image webcontrol, but system.web.ui.webcontrols.image only seems to have a control to load the image from a URL. There's no way to load this directly without saving the image as a file and then using...
10
7420
by: Nathan Sokalski | last post by:
I am using ASP.NET 2.0, and need to know how to save and use an image that is stored in an SQL Server image datatype. How can I do this using ASP.NET? Thanks.
0
8324
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8842
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8740
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8516
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8617
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5642
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.