If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Issue with displaying image on form
Access 2007
I am able to get my form to display a unique linked image for every record. The image displayed is based on the name of the file stored in a text field - [CAD FILE]. The problem I am having is that if I am on a record then go to another record, if a file doesn't exist matching what is in [CAD FILE] it will continue to show the image from the previously viewed record. What can I do to get it to display my default file ("-.jpg") if there is no file name matching [CAD FILE]? (yes, the file is named "-.jpg"; is this a problem for any reason?) This is the code I did this with a *******ization of the code from the downloaded Picture2K db: Option Compare Database Option Explicit Private Sub cmdClose_Click() On Error Resume Next DoCmd.Close Exit Sub End Sub Private Sub Form_AfterUpdate() On Error Resume Next Me![Image39].Picture = "\\UNCfilepath\" & [CAD FILE] & ".jpg" End Sub Private Sub Form_Current() On Error Resume Next Me![Image39].Picture = "\\UNCfilepath\" & [CAD FILE] & ".jpg" End Sub Private Sub Image39_Click() End Sub |
#2
|
|||
|
|||
Issue with displaying image on form
On Wed, 10 Feb 2010 16:09:02 -0800, MSACSNewb
wrote: You can test for existence of the file in Form_Current using the Dir function: Private Sub Form_Current() dim strFile as string strFile = "\\UNCfilepath\" & [CAD FILE] & ".jpg" if Dir(strFile) = "" then strFile = "\\UNCfilepath\-.jpg" end if Me.myCadFileControl.Picture = strFile End Sub Note how I also named your picture control appropriately, and got rid of the ugly "on error resume next". -Tom. Microsoft Access MVP Access 2007 I am able to get my form to display a unique linked image for every record. The image displayed is based on the name of the file stored in a text field - [CAD FILE]. The problem I am having is that if I am on a record then go to another record, if a file doesn't exist matching what is in [CAD FILE] it will continue to show the image from the previously viewed record. What can I do to get it to display my default file ("-.jpg") if there is no file name matching [CAD FILE]? (yes, the file is named "-.jpg"; is this a problem for any reason?) This is the code I did this with a *******ization of the code from the downloaded Picture2K db: Option Compare Database Option Explicit Private Sub cmdClose_Click() On Error Resume Next DoCmd.Close Exit Sub End Sub Private Sub Form_AfterUpdate() On Error Resume Next Me![Image39].Picture = "\\UNCfilepath\" & [CAD FILE] & ".jpg" End Sub Private Sub Form_Current() On Error Resume Next Me![Image39].Picture = "\\UNCfilepath\" & [CAD FILE] & ".jpg" End Sub Private Sub Image39_Click() End Sub |
#3
|
|||
|
|||
Issue with displaying image on form
Sorry, I do not know VB at all. I understand what the original code did, but
don't really know how? I don't "speak the language" so to speak... So are you saying to replace ALL my existing code with the code you supplied? If not all, then where would I place it? Thanks for the help! "Tom van Stiphout" wrote: On Wed, 10 Feb 2010 16:09:02 -0800, MSACSNewb wrote: You can test for existence of the file in Form_Current using the Dir function: Private Sub Form_Current() dim strFile as string strFile = "\\UNCfilepath\" & [CAD FILE] & ".jpg" if Dir(strFile) = "" then strFile = "\\UNCfilepath\-.jpg" end if Me.myCadFileControl.Picture = strFile End Sub Note how I also named your picture control appropriately, and got rid of the ugly "on error resume next". -Tom. Microsoft Access MVP Access 2007 I am able to get my form to display a unique linked image for every record. The image displayed is based on the name of the file stored in a text field - [CAD FILE]. The problem I am having is that if I am on a record then go to another record, if a file doesn't exist matching what is in [CAD FILE] it will continue to show the image from the previously viewed record. What can I do to get it to display my default file ("-.jpg") if there is no file name matching [CAD FILE]? (yes, the file is named "-.jpg"; is this a problem for any reason?) This is the code I did this with a *******ization of the code from the downloaded Picture2K db: Option Compare Database Option Explicit Private Sub cmdClose_Click() On Error Resume Next DoCmd.Close Exit Sub End Sub Private Sub Form_AfterUpdate() On Error Resume Next Me![Image39].Picture = "\\UNCfilepath\" & [CAD FILE] & ".jpg" End Sub Private Sub Form_Current() On Error Resume Next Me![Image39].Picture = "\\UNCfilepath\" & [CAD FILE] & ".jpg" End Sub Private Sub Image39_Click() End Sub . |
#4
|
|||
|
|||
Issue with displaying image on form
On Thu, 11 Feb 2010 12:04:03 -0800, MSACSNewb
wrote: No, and I didn't say that. My code is a replacement for the Form_Current event. If you don't speak VBA, it's probably best not to attempt to change the code. I would recommend brushing up on your programming skills, or hiring someone who can make these and other quality-related changes for you. For example the use of "on error resume next" is rarely a good idea. -Tom. Microsoft Access MVP Sorry, I do not know VB at all. I understand what the original code did, but don't really know how? I don't "speak the language" so to speak... So are you saying to replace ALL my existing code with the code you supplied? If not all, then where would I place it? Thanks for the help! "Tom van Stiphout" wrote: On Wed, 10 Feb 2010 16:09:02 -0800, MSACSNewb wrote: You can test for existence of the file in Form_Current using the Dir function: Private Sub Form_Current() dim strFile as string strFile = "\\UNCfilepath\" & [CAD FILE] & ".jpg" if Dir(strFile) = "" then strFile = "\\UNCfilepath\-.jpg" end if Me.myCadFileControl.Picture = strFile End Sub Note how I also named your picture control appropriately, and got rid of the ugly "on error resume next". -Tom. Microsoft Access MVP Access 2007 I am able to get my form to display a unique linked image for every record. The image displayed is based on the name of the file stored in a text field - [CAD FILE]. The problem I am having is that if I am on a record then go to another record, if a file doesn't exist matching what is in [CAD FILE] it will continue to show the image from the previously viewed record. What can I do to get it to display my default file ("-.jpg") if there is no file name matching [CAD FILE]? (yes, the file is named "-.jpg"; is this a problem for any reason?) This is the code I did this with a *******ization of the code from the downloaded Picture2K db: Option Compare Database Option Explicit Private Sub cmdClose_Click() On Error Resume Next DoCmd.Close Exit Sub End Sub Private Sub Form_AfterUpdate() On Error Resume Next Me![Image39].Picture = "\\UNCfilepath\" & [CAD FILE] & ".jpg" End Sub Private Sub Form_Current() On Error Resume Next Me![Image39].Picture = "\\UNCfilepath\" & [CAD FILE] & ".jpg" End Sub Private Sub Image39_Click() End Sub . |
#5
|
|||
|
|||
Issue with displaying image on form
Sorry, I ran out of time before leaving work yesterday to follow up on this.
I did some trial and error and got this to work. My code is a replacement for the Form_Current event. I replaced both the Form_Current and Form_AfterUpdate events with the code you supplied and it works great. Thanks again for that!!! If you don't speak VBA, it's probably best not to attempt to change the code. I would recommend brushing up on your programming skills, or hiring someone who can make these and other quality-related changes for you. This is me brushing up on programming. I have made more sense out of trying to do something and then making it work through trial and error then in the classes I took at the CC. The realworld examples set in better than the textbook examples. Again thanks to you and all he people here for providing this support! For example the use of "on error resume next" is rarely a good idea. In my searches here to find a way to get images to appear in a form, I kept running into the advice of downloading the Picture2k DB and studying the code to see how it worked. I did that but it had you create a new table and save the file path in one field and the file name in another. It didn't make sense to me to store the file path repeatedly and I already store the file name in a field in my main table [CAD FILE]. I add 2-10 new records and theoreticly 2-10 new PDF files and correponding thumbnail images every day; ~9500 records in main table. So to have the file path stored 9500 times (and growing) didn't make sense. The Picture2k DB might go back a few years and a few versions of Access so maybe the "on error resume next" made more sense then? This is the actual code fom the Picture2k DB: Option Compare Database Option Explicit Private Sub cmdClose_Click() On Error Resume Next DoCmd.Close Exit Sub End Sub Private Sub Form_AfterUpdate() On Error Resume Next Me![ImageFrame].Picture = Me![FilePath] & Me![FileName] ***I replaced everything after "=" with "\\UNCfilepath\" & [CAD FILE] & ".jpg" and was pleasanty suprised it worked!*** Me![txtPath] = Me![FilePath] & Me![FileName] ***I didn't use this as I only wanted the image control*** End Sub Private Sub Form_Current() On Error Resume Next Me![ImageFrame].Picture = Me![FilePath] & Me![FileName] Me![txtPath] = Me![FilePath] & Me![FileName] End Sub Private Sub ImageFrame_Click() End Sub |
Thread Tools | |
Display Modes | |
|
|