open a form with special "Where" condition

  • Thread starter Thread starter Beth
  • Start date Start date
B

Beth

I have a form (frmWorkers) based on a query combining 2 tables. The form
works great. However, I would like to be able to use a second button on my
switchboard that opens the same form, but only where a checkbox (available)
is checked. The problem is that the form opens with a blank recordset and I
have confirmed that there should be entries.
Any help you can provide is appreciated.
Beth

Here is the code I used on the button on the switchboard.

Private Sub cmdAvailableWorkers_Click()
On Error GoTo Err_Workers
DoCmd.OpenForm "Workers", , , "Forms![Workers]![Available] = True"
DoCmd.Maximize
Exit Sub

Err_Workers:
Select Case (Err)
Case 2603
DoCmd.CancelEvent
DoCmd.SetWarnings (WarningsOff)
X = MsgBox("You do not have access to this feature.", , "Contact
Administrator")

Case Else
X = MsgBox(Err.Description, , "Error")
Exit Sub

End Select
End Sub
 
Beth said:
I have a form (frmWorkers) based on a query combining 2 tables. The
form works great. However, I would like to be able to use a second
button on my switchboard that opens the same form, but only where a
checkbox (available) is checked. The problem is that the form opens
with a blank recordset and I have confirmed that there should be
entries.
Any help you can provide is appreciated.
Beth

Here is the code I used on the button on the switchboard.
[snip]
DoCmd.OpenForm "Workers", , , "Forms![Workers]![Available] = True"
[snip]

Your where-condition should just refer to the field in the form's
recordsource, not to the control on the form. Assuming "Available" is
the name of the field, try this:

DoCmd.OpenForm "Workers", , , "Available = True"
 
Thank you, it works perfectly.
Beth
Dirk Goldgar said:
Beth said:
I have a form (frmWorkers) based on a query combining 2 tables. The
form works great. However, I would like to be able to use a second
button on my switchboard that opens the same form, but only where a
checkbox (available) is checked. The problem is that the form opens
with a blank recordset and I have confirmed that there should be
entries.
Any help you can provide is appreciated.
Beth

Here is the code I used on the button on the switchboard.
[snip]
DoCmd.OpenForm "Workers", , , "Forms![Workers]![Available] = True"
[snip]

Your where-condition should just refer to the field in the form's
recordsource, not to the control on the form. Assuming "Available" is
the name of the field, try this:

DoCmd.OpenForm "Workers", , , "Available = True"

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Back
Top