Forms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form that is invoked by a command button on a Main Form. The data
for the form is based on SQL. I want to add another command button that
opens the same form but with the SQL modified to include a filter criteria,
based on a Yes/No field in a table, rather than creating a duplicate form
with a different name with slightly different SQL. Creating a duplicate form
would create headaches, since I would have to change all references to the
form name in VBA and a couple of queries used in the form. Is there a way to
do this?

Thanks -- Garry Gross
 
Hi Garry,

Have you tried using the WhereCondition argument of the DoCmd.Openform
method? Something like this example, which works in the Northwind sample
database:

Option Compare Database
Option Explicit

Private Sub cmdCurrentProducts_Click()

On Error GoTo ProcError

DoCmd.openForm FormName:="Products", _
WhereCondition:="Discontinued =0"

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure cmdCurrentProducts_Click..."
Resume ExitProc
End Sub


Private Sub cmdDiscontinuedProducts_Click()

On Error GoTo ProcError

DoCmd.openForm FormName:="Products", _
WhereCondition:="Discontinued <>0"

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure cmdDiscontinuedProducts_Click..."
Resume ExitProc
End Sub

Tom

http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 
Thanks- Your response also made me remember something else - Macros have a
"Where Condition". I tried that also, and it works fine.

Garry
 
Hi Garry,

I didn't suggest the use of macros, because I tend to avoid them myself.

Glad I could be of help. Thank You for marking my response as an answer.
This is appreciated.


Tom

http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________

:

Thanks- Your response also made me remember something else - Macros have a
"Where Condition". I tried that also, and it works fine.

Garry
__________________________________________

:

Hi Garry,

Have you tried using the WhereCondition argument of the DoCmd.Openform
method? Something like this example, which works in the Northwind sample
database:

Option Compare Database
Option Explicit

Private Sub cmdCurrentProducts_Click()

On Error GoTo ProcError

DoCmd.openForm FormName:="Products", _
WhereCondition:="Discontinued =0"

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure cmdCurrentProducts_Click..."
Resume ExitProc
End Sub


Private Sub cmdDiscontinuedProducts_Click()

On Error GoTo ProcError

DoCmd.openForm FormName:="Products", _
WhereCondition:="Discontinued <>0"

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure cmdDiscontinuedProducts_Click..."
Resume ExitProc
End Sub

Tom

http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top