Entering Pictures in a form geting an error

G

Gina Whipp

desireemm,

Removed previous postings so as to avoid confusion. DO THIS ON A BACK-UP...
If you make a boo-boo you want to retain the original!!!

Step 1

Copy and Paste the below in a module and named modImages and save when done

***START OF CODE***
Option Compare Database
Option Explicit
Public Function DisplayImage(ctlImageControl As Control, strImagePath As
Variant) As String
On Error GoTo Err_DisplayImage

Dim strResult As String
Dim strDatabasePath As String
Dim intSlashLocation As Integer

With ctlImageControl
If IsNull(strImagePath) Then
.Visible = False
strResult = "No image name specified."
Else
If InStr(1, strImagePath, "\") = 0 Then
' Path is relative
strDatabasePath = CurrentProject.FullName
intSlashLocation = InStrRev(strDatabasePath, "\",
Len(strDatabasePath))
strDatabasePath = Left(strDatabasePath, intSlashLocation)
strImagePath = strDatabasePath & strImagePath
End If
.Visible = True
.Picture = strImagePath
strResult = "Image found and displayed."
End If
End With

Exit_DisplayImage:
DisplayImage = strResult
Exit Function

Err_DisplayImage:
Select Case Err.Number
Case 2220 ' Can't find the picture.
ctlImageControl.Visible = False
strResult = "Can't find image in the specified name."
Resume Exit_DisplayImage:
Case Else ' Some other error.
MsgBox Err.Number & " " & Err.Description
strResult = "An error occurred displaying image."
Resume Exit_DisplayImage:
End Select
End Function
***END OF CODE***

Step 2
In your table you will need two fields ImagePath and ImageNote

Step 3 - Do following while form is in Design View
a. On your form place both fields and name then txtImagePath and
txtImageNote
b. Also add an Image Control, unbound and name it imgImage NOTE: While
adding this control it wants you to select an Image, do it and after you
have created the control go to Properties and remove anything on the Picture
line. It will ask you a question and YES you want to set the picture to
*NONE*.)

Step 4 - Still in Design View of the form
Place two command buttons, one named cmdAddImage (Make the caption say the
same) the other name cmdClearImage (Make the caption say the same). Below
is the code for the buttons... Place the code in the On_Click event of the
prospective buttons...

'***cmdAddAimage****

' Purpose : Use the API to open the Windows Common Dialog for the user to
select a file
' Parameters : Cancel -- if set to true on Exit, cancels opening the form
' Created: 6/24/99
'On Error GoTo ErrHandler
Dim lngFlags As Long
Dim strFilter As String
Dim strPathAndFile As String
Me.AllowDeletions = False
strFilter = ahtAddFilterItem(strFilter, "Compressed Image Files (*.jpg,
*.jff, *.gif, *.tiff )", "*.JPG;*.JFF,*.GIF,*.TIF")
strFilter = ahtAddFilterItem(strFilter, "Uncompressed Image Files
(*.bmp, *.wmf)", "*.BMP, *.WMF")
strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")
strPathAndFile = ahtCommonFileOpenSave(InitialDir:="S:\Cleveland\Jobs\",
Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, DialogTitle:="Choose an
Image")
If Len(strPathAndFile) > 0 Then
Me.txtImagePath = strPathAndFile
Me.imgImage.Picture = Me.txtImagePath
Else
MsgBox "You didn't select a file", , "Images"
DoCmd.CancelEvent
End If
' Since you passed in a variable for lngFlags,
' the function places the output flags value in the variable.
Exit_Sub:
Exit Sub
ErrHandler:
MsgBox "Error " & Err.Number & " : " & Err.Description & " in
Form_Open", vbExclamation, "Images in Access Example"
Resume Exit_Sub
'***END OF CODE


'***cmdClearImage

On Error Resume Next
Me.txtImagePath = Null
Me.imgImage.Picture = ""
'***END OF CODE

Step 4 - Save but remain in Design View of the form. Copy paste the code
below at the bottom of the Code WIndow and Save

'***START OF CODE
Private Sub CallDisplayImage()
Me!txtImageNote = DisplayImage(Me!imgImage, Me!txtImagePath)
End Sub
'***END OF CODE

Step 5

Place...

CallDisplayImage

....on the After_Update of the form OR On_Current of the form AND in the
After_Update of txtImagePath


ALL DONE! Now all you need to do is load the image paths into the database.

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm
 
D

desireemm

thank you Gina, I will give it a try on a back up and let you know the
results thanks again

Gina Whipp said:
Just a thought, perhaps the below will be easier...

Main form

Subform attached to Main form - OLE Object on this form
RecordSource should be a query

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

desireemm said:
Hi Gina I did save record souce, this is the record souce for the form
that I
insert the pictures into. And the Field is an Image field, I have done
this
before and not had any problems now for some reason I am having problems.
But if I make that form into a sub form on the main form it works fine.
so
I'm confused. the image is an ole object I guess

SELECT PeopleID, Image, PicID, ParentID FROM AdultPics_tbl

Gina Whipp said:
Okay, I think I may be asking this incorrectly...

You have a form thru which you insert pictures... How do you insert the
pictures? The code you show below simply opens the pictures form. If
that
is the form where you recieve the error then THAT form needs to have it's
RecordSource saved as a query.

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" -
Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

here is what the command button usese

Private Sub Command439_Click()
On Error GoTo Err_Command439_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "ClientPictures_fm"

stLinkCriteria = "[PeopleID]=" & Me![PeopleID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command439_Click:
Exit Sub

Err_Command439_Click:
MsgBox Err.Description
Resume Exit_Command439_Click

End Sub


:

Error mesage?

Also, can you copy/paste the code the Command Button is using?

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" -
Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

it still didnt work, it does work if I make the picture form a
subform
and
enter pictures but it doesnnt work when I access it through a
command
button.


:

desireemm,

Okay now the error message...

This error can occur if the data you are attempting to save is
saving
to
a
Microsoft SQL Server 7.0 or earlier database and the RecordSource
for
the
subform is using an SQL select statement with fields pulled
directly
from
the
source table, and the table is using an Identity field set as its
primary
key.
*****To avoid this problem set the RecordSource property of the
subform
to a
table or a query.*****

Because of your version of SQL Server you will need to turn you
SELECT
statement into a QUERY. Make the QUERY the RecordSource of the
form.
To
do
that...

1. Go back to Design View of the Form and return to the
RecordSource
and
click the elipse button [...].
2. Once that window open press the SAVE button and name your query
and
save. Say "Yes" or "Okay" to all questions and try your insert
picture
again.

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" -
Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

ok Here is the Record source

SELECT [Parent ID], [Family ID], [Referral Location], [Referral
Date],
[Registration Date], [Student First Name], [Student SS#],
[Student
Last
Name], [Student Sex], Grade, Age, [Student Date of Birth], [Event
ID],
TANFreferral, TypeOfParticipant, RequiredHours,
SpecialInstructions,
Adult_Child, State, SSID, PeopleID, TANF, ServiceArea, Weekly,
Month,
ReferralStatus, TanfStaffMakeReferal, Message, Phone,
StateStudentID,
TribalAfflilation, StudentCity, StudentState, StudentZip,
StudentAddress,
DateReleased, StudentRelease, ParentRelease, ScannedDocuments,
EmailAddress,
Enrollmentstatus, MaritalStatus, Vetran, TanfSpouseName,
TanfSpouseSocial,
PntID, Pictures FROM TANFParticipants_view

:

Okay, that s not what I want...

Go to the form which you use to enter the pictures (in the
Access
database)
Go to Design View of that form and pull up the properties
In the Properties section at the top it will RecordSource...
copy
and
paste
that here.

--
Gina Whipp

"I feel I have been denied critical, need to know,
information!" -
Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

message
I hope I am understanding you. this is the record source
Picture is an Image, PicID is Interget (Identiy/SqL
Autonumber)
only
parent
is nvarchar (50)

SELECT Picture, PicID, PeopleID, [Parent ID] FROM
TanfPictures_tbl

:

And the RecordSoirce of the form?

--
Gina Whipp

"I feel I have been denied critical, need to know,
information!" -
Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

message
I'm sorry Its Access 2007 with SQL server 2005 as the
engine.
Yes
the
pictures are stored in a table which only stores pics

:

desireemm,

We're going to need a little help here...

Access version?
Are you, in fact, using SQL Server 7.0 or earlier or
another
version?
Are you storing the pictures in the database or rather
trying
to
store
them
in the database?
What is the RecordSource of the form?

....that should get us started.

--
Gina Whipp

"I feel I have been denied critical, need to know,
information!" -
Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

message
Hi all I have a table called Pictures_tbl that has a one
to
many
relationship
with a parent table called People_tbl. Every time I
enter a
picture
into
the
form where the Pictures_tbl is I get this error message.
Can
anyone
help.


This error can occur if the data you are attempting to
save
is
saving
to a
Microsoft SQL Server 7.0 or earlier database and the
RecordSource
for
the
subform is using an SQL select statement with fields
pulled
directly
from
the
source table, and the table is using an Identity field
set
as
its
 
G

Gina Whipp

Okie dokie...

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

desireemm said:
thank you Gina, I will give it a try on a back up and let you know the
results thanks again

Gina Whipp said:
Just a thought, perhaps the below will be easier...

Main form

Subform attached to Main form - OLE Object on this form
RecordSource should be a query

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" -
Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

desireemm said:
Hi Gina I did save record souce, this is the record souce for the form
that I
insert the pictures into. And the Field is an Image field, I have done
this
before and not had any problems now for some reason I am having
problems.
But if I make that form into a sub form on the main form it works fine.
so
I'm confused. the image is an ole object I guess

SELECT PeopleID, Image, PicID, ParentID FROM AdultPics_tbl

:

Okay, I think I may be asking this incorrectly...

You have a form thru which you insert pictures... How do you insert
the
pictures? The code you show below simply opens the pictures form. If
that
is the form where you recieve the error then THAT form needs to have
it's
RecordSource saved as a query.

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" -
Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

here is what the command button usese

Private Sub Command439_Click()
On Error GoTo Err_Command439_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "ClientPictures_fm"

stLinkCriteria = "[PeopleID]=" & Me![PeopleID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command439_Click:
Exit Sub

Err_Command439_Click:
MsgBox Err.Description
Resume Exit_Command439_Click

End Sub


:

Error mesage?

Also, can you copy/paste the code the Command Button is using?

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" -
Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

it still didnt work, it does work if I make the picture form a
subform
and
enter pictures but it doesnnt work when I access it through a
command
button.


:

desireemm,

Okay now the error message...

This error can occur if the data you are attempting to save is
saving
to
a
Microsoft SQL Server 7.0 or earlier database and the
RecordSource
for
the
subform is using an SQL select statement with fields pulled
directly
from
the
source table, and the table is using an Identity field set as
its
primary
key.
*****To avoid this problem set the RecordSource property of the
subform
to a
table or a query.*****

Because of your version of SQL Server you will need to turn you
SELECT
statement into a QUERY. Make the QUERY the RecordSource of the
form.
To
do
that...

1. Go back to Design View of the Form and return to the
RecordSource
and
click the elipse button [...].
2. Once that window open press the SAVE button and name your
query
and
save. Say "Yes" or "Okay" to all questions and try your insert
picture
again.

--
Gina Whipp

"I feel I have been denied critical, need to know,
information!" -
Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

message
ok Here is the Record source

SELECT [Parent ID], [Family ID], [Referral Location],
[Referral
Date],
[Registration Date], [Student First Name], [Student SS#],
[Student
Last
Name], [Student Sex], Grade, Age, [Student Date of Birth],
[Event
ID],
TANFreferral, TypeOfParticipant, RequiredHours,
SpecialInstructions,
Adult_Child, State, SSID, PeopleID, TANF, ServiceArea, Weekly,
Month,
ReferralStatus, TanfStaffMakeReferal, Message, Phone,
StateStudentID,
TribalAfflilation, StudentCity, StudentState, StudentZip,
StudentAddress,
DateReleased, StudentRelease, ParentRelease, ScannedDocuments,
EmailAddress,
Enrollmentstatus, MaritalStatus, Vetran, TanfSpouseName,
TanfSpouseSocial,
PntID, Pictures FROM TANFParticipants_view

:

Okay, that s not what I want...

Go to the form which you use to enter the pictures (in the
Access
database)
Go to Design View of that form and pull up the properties
In the Properties section at the top it will RecordSource...
copy
and
paste
that here.

--
Gina Whipp

"I feel I have been denied critical, need to know,
information!" -
Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

message
I hope I am understanding you. this is the record source
Picture is an Image, PicID is Interget (Identiy/SqL
Autonumber)
only
parent
is nvarchar (50)

SELECT Picture, PicID, PeopleID, [Parent ID] FROM
TanfPictures_tbl

:

And the RecordSoirce of the form?

--
Gina Whipp

"I feel I have been denied critical, need to know,
information!" -
Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

message
I'm sorry Its Access 2007 with SQL server 2005 as the
engine.
Yes
the
pictures are stored in a table which only stores pics

:

desireemm,

We're going to need a little help here...

Access version?
Are you, in fact, using SQL Server 7.0 or earlier or
another
version?
Are you storing the pictures in the database or rather
trying
to
store
them
in the database?
What is the RecordSource of the form?

....that should get us started.

--
Gina Whipp

"I feel I have been denied critical, need to know,
information!" -
Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

in
message
Hi all I have a table called Pictures_tbl that has a
one
to
many
relationship
with a parent table called People_tbl. Every time I
enter a
picture
into
the
form where the Pictures_tbl is I get this error
message.
Can
anyone
help.


This error can occur if the data you are attempting
to
save
is
saving
to a
Microsoft SQL Server 7.0 or earlier database and the
RecordSource
for
the
subform is using an SQL select statement with fields
pulled
directly
from
the
source table, and the table is using an Identity
field
set
as
its
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top