Nathan87
Registered User.
- Local time
- Today, 09:57
- Joined
- Mar 8, 2013
- Messages
- 20
I have a query that works as expected when I just open it and type a number for the parameter field, but when it is called through VBA it seems to be functioning differently.
Here is the query:
When run through vba the criteria for default being true and deleted being false don't seem to work. If I have 3 pictures and only one is selected as default only one should be match, but when run through VBA if I have 3 pictures and one is selected as Default (meaning value of True) then all 3 pictures are returned by the query. When ran manually though only 1 record is returned.
Here is how I'm calling the query in the script and how I'm checking the number of returned records:
Any ideas of what could be going wrong here?
Here is the query:
Code:
SELECT AttachmentTable.ID, AttachmentTable.ItemID, AttachmentTable.Type,
AttachmentTable.AttachmentName, AttachmentTable.Default, AttachmentTable.Deleted
FROM AttachmentTable
WHERE (
(AttachmentTable.ItemID=[IDfilter]) And
(AttachmentTable.Type=1) And
(AttachmentTable.Default=True) And
(AttachmentTable.Deleted=False));
Here is how I'm calling the query in the script and how I'm checking the number of returned records:
Code:
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
Dim intRecordCount As Integer
Set db = CurrentDb
Set qdf = db.QueryDefs("DefaultPictureQry")
qdf.Parameters("IDfilter").Value = Forms![ItemDetailTable]![ID]
'qdf.Parameters("IDfilter").Value = 1
Set rs = qdf.OpenRecordset
intRecordCount = rs.RecordCount
Any ideas of what could be going wrong here?