G
Guest
I have a database with two tables - a Work Order table and a Preventive
Maintenance (PM) schedule table. I am also using the Access Switchboard when
the database is opened.
In the normal Database view, I created an update query (PMCreateOrders) that
will check for due dates in the PM table, and then Append these records to
the Work Order table so a Work Order can be generated.
In the Switchboard form's Open command, I tried to use the OpenRecordset
method on the Update query to determine if ant records need to be created and
appended to the Work Order table. It fails. So, I thought perhaps a Recordset
is not generated during an Update query. I created a Select query
(PMPendingOrders) on the PM table and can create a recordset via
OpenRecordset. Then, I check if the number of records in the recordset is
greater than zero. If so, I then the Update query and a third query not
involved in this question.
My code is below. Is there a way to determine if PM records need to be
appended to the Work Order table without first running the Select query? And,
should I change the DoCmd.OpenQuery commands to Execute commands?
Private Sub Form_Open(Cancel As Integer)
' Minimize the database window and initialize the form.
Dim dbs As Database
Dim rst As DAO.Recordset
' Move to the switchboard page that is marked as the default.
Me.Filter = "[ItemNumber] = 0 AND [Argument] = 'Default' "
Me.FilterOn = True
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("PMPendingOrders", dbOpenDynaset, dbReadOnly)
If rst.RecordCount > 0 Then
DoCmd.OpenQuery "PMCreateOrder", , acReadOnly
DoCmd.OpenQuery "PMUpdateTable", , acReadOnly
End If
End Sub
Maintenance (PM) schedule table. I am also using the Access Switchboard when
the database is opened.
In the normal Database view, I created an update query (PMCreateOrders) that
will check for due dates in the PM table, and then Append these records to
the Work Order table so a Work Order can be generated.
In the Switchboard form's Open command, I tried to use the OpenRecordset
method on the Update query to determine if ant records need to be created and
appended to the Work Order table. It fails. So, I thought perhaps a Recordset
is not generated during an Update query. I created a Select query
(PMPendingOrders) on the PM table and can create a recordset via
OpenRecordset. Then, I check if the number of records in the recordset is
greater than zero. If so, I then the Update query and a third query not
involved in this question.
My code is below. Is there a way to determine if PM records need to be
appended to the Work Order table without first running the Select query? And,
should I change the DoCmd.OpenQuery commands to Execute commands?
Private Sub Form_Open(Cancel As Integer)
' Minimize the database window and initialize the form.
Dim dbs As Database
Dim rst As DAO.Recordset
' Move to the switchboard page that is marked as the default.
Me.Filter = "[ItemNumber] = 0 AND [Argument] = 'Default' "
Me.FilterOn = True
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("PMPendingOrders", dbOpenDynaset, dbReadOnly)
If rst.RecordCount > 0 Then
DoCmd.OpenQuery "PMCreateOrder", , acReadOnly
DoCmd.OpenQuery "PMUpdateTable", , acReadOnly
End If
End Sub