Access button to insert photos

  • Thread starter Thread starter tpalmer00
  • Start date Start date
T

tpalmer00

Hi,

I want to create a button in Access that will allow users to browse for and
insert a photo. I'm using the code below:

Private Sub Photo1_Click()
Photo.SetFocus
DoCmd.RunCommand acCmdInsertObject

This works fine except for when you hit the cancel button. I get a run-time
error of '2501'. Can anyone suggest an alternative?

Thanks,
Trish


Private Sub Photo1_Click()
Photo.SetFocus
DoCmd.RunCommand acCmdInsertObject
 
The error should not pose you a problem. Simply use basic error trapping to
ignore it so it doesn't get returned to the user.

On error goto errhandle

'your code

errhandler:
if err.number <> 2501 then
msgbox err.number & vbcrlf & vbcrlf & err.description
End if
Exit Sub
 
Personally, I wouldn't insert a photo *into* the database. The usual advice
is to store the photo on the file system and just store the path to it in
the database. On my website (www.rogersaccesslibrary.com), is a small
Access database sample called "PicturesLoad.mdb" which illustrates how to do
this.

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 
Back
Top