Nathan87
Registered User.
- Local time
- Today, 11:44
- Joined
- Mar 8, 2013
- Messages
- 20
Hello,
I have a form that I would like to update a picture on using VBA. The source of the picture path is in part a query that is not bound to the form. So far I have the following code that is pretty much working, but with a couple flaws.
This is working. However, when I change the record the picture flashes the current picture once and then loads the new picture. It is like it reloads the current picture then loads the new one. I'm hoping there is a way to get rid of the flash.
Also, the code fails here:
strDefaultPictureName = rs.Fields("AttachmentName")
when the query does not return a record. I can definitely fix this by adding an if statement to check for a record, but I'm kind of perplexed at why it is failing at that line. I would expect it to assign an empty string to that variable name and then fail on the next command where I try and set the ".Picture" property of the image.
If anyone could shed some light on the couple of issues it would be a big help.
Thanks.
I have a form that I would like to update a picture on using VBA. The source of the picture path is in part a query that is not bound to the form. So far I have the following code that is pretty much working, but with a couple flaws.
Code:
Private Sub Form_Current()
LoadDefaultPicture
End Sub
Sub LoadDefaultPicture()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim prm As DAO.Parameter
Dim rs As DAO.Recordset
Dim strFolderPath As String
Dim strDefaultPictureName As String
Set db = CurrentDb
Set qdf = db.QueryDefs("DefaultPictureQry")
qdf.Parameters("IDfilter").Value = Forms![ItemDetailTable]![ID]
Set rs = qdf.OpenRecordset
strFolderPath = Forms![ItemDetailTable]!AttachmentFolderPath
strDefaultPictureName = rs.Fields("AttachmentName")
Forms![ItemDetailTable]![DefaultPicture].Picture _
= strFolderPath & strDefaultPictureName
End Sub
Also, the code fails here:
strDefaultPictureName = rs.Fields("AttachmentName")
when the query does not return a record. I can definitely fix this by adding an if statement to check for a record, but I'm kind of perplexed at why it is failing at that line. I would expect it to assign an empty string to that variable name and then fail on the next command where I try and set the ".Picture" property of the image.
If anyone could shed some light on the couple of issues it would be a big help.
Thanks.