hondaman2003
Programmer
Can anyone see why this command will not work? The problem is the query doesn't find any records.
DoCmd.RunSQL "UPDATE [Patient table] SET [Owner2] = '" & [LAN ID - 1] & "' WHERE [Patient table].[Owner2] IN (SELECT TOP 2 [Patient Table].Owner2 FROM [Patient Table] WHERE ((([Patient Table].Owner2) Is Null Or ([Patient Table].Owner2)='') AND (([Patient Table].Completed2)=0)));"
The highlevel over view of this database is, people work records. We assign out records to be worked based on there "LAN ID". We have a form that will only show records where the LAN ID match who they are. The point to this command is to assign the LAN ID to the field 'Owner' in a certain number of records. The way it assigns records is if the 'Owner' field on a table is blank and the 'Completed' check box is not checked. On the form there is a field called 'LAN ID - 1' that is to be assigned to a certain number of records. That number of records is determined by the number '2' I hard coded into the command. I will change that so it pulls from the form.
When I pull the subquery out and run it on it's own, it will find the correct number of records. When I save the subquery as it's own query, then run the update query, it update the correct number of records. I can even run this entire command as a query and it will work. It will just not work if I run it in VBA.
DoCmd.RunSQL "UPDATE [Patient table] SET [Owner2] = '" & [LAN ID - 1] & "' WHERE [Patient table].[Owner2] IN (SELECT TOP 2 [Patient Table].Owner2 FROM [Patient Table] WHERE ((([Patient Table].Owner2) Is Null Or ([Patient Table].Owner2)='') AND (([Patient Table].Completed2)=0)));"
The highlevel over view of this database is, people work records. We assign out records to be worked based on there "LAN ID". We have a form that will only show records where the LAN ID match who they are. The point to this command is to assign the LAN ID to the field 'Owner' in a certain number of records. The way it assigns records is if the 'Owner' field on a table is blank and the 'Completed' check box is not checked. On the form there is a field called 'LAN ID - 1' that is to be assigned to a certain number of records. That number of records is determined by the number '2' I hard coded into the command. I will change that so it pulls from the form.
When I pull the subquery out and run it on it's own, it will find the correct number of records. When I save the subquery as it's own query, then run the update query, it update the correct number of records. I can even run this entire command as a query and it will work. It will just not work if I run it in VBA.