Conditional command button

D

dwilliamson

MS Access 2002...
I have a database with a "facility type" equal to a drop down list of 5
variables (residential, commercial, municipal, etc). I am trying to create a
command button on this form that will open the correct inspection form based
on the facility type. So, if residential is selected for the facility type
and the "enter inspections" command button is clicked I want the residential
inspection form to open up.
 
A

akphidelt

Yes you can, but the only way I know how is through VBA. So you can do
something like

Right click on the button, go to build event... click on Code
Or you can go to the properties, go to events, and click on the On Click event

Type in the code

Select Case Me.Combobox

Case "Residential"
DoCmd.OpenForm "FormResidential"
Case "Commercial"
DoCmd.OpenForm "FormCommercial"

End Select

You would type in as many cases as you want... I just was showing you an
example of how it would look with a select case scenario.
 
D

dwilliamson

Thank you for your response and I believe we are heading in the right
direction, pasted below is the code that I have entered and right now I get
nothing. No errors, no inspection forms open, nothing. The SITUS_ID are to
make sure the inspection form that opens is linked to the current facility.
SITUS_Facility_Type is the the dropdown list of the various facility types.

Private Sub Command55_Click()
On Error GoTo Err_Command55_Click


Dim stLinkCriteria As String
stLinkCriteria = "[SITUS_ID]=" & Me![SITUS_ID]


Select Case Me.SITUS_Facility_Type

Case "Residential"
DoCmd.OpenForm frm_inspection_residential, , , stLinkCriteria
Case "Commercial"
DoCmd.OpenForm FRM_INSPECTION, , , stLinkCriteria

End Select



Exit_Command55_Click:
Exit Sub

Err_Command55_Click:
MsgBox Err.Description
Resume Exit_Command55_Click

End Sub
 
D

dwilliamson

IT WORKS! - while waiting for a reply and doing a little more research I
found the problem and it now works. below is the code that was successful.
Thanks for all the help. that crucial part that was missing was the
..column(1) to tell the select case statement which field of the combo box to
look in for the variable. Again thanks for the help.

Private Sub Command54_Click()
On Error GoTo Err_Command54_Click

Dim stDocName As String
Dim stLinkCriteria As String

Select Case Me!SITUS_Facility_Type.Column(1)

Case "Residential"
stDocName = "frm_inspection_residential"
Case "Commercial"
stDocName = "FRM_INSPECTION"

End Select

'stDocName = "frm_inspection_residential"

stLinkCriteria = "[SITUS_ID]=" & Me![SITUS_ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command54_Click:
Exit Sub

Err_Command54_Click:
MsgBox Err.Description
Resume Exit_Command54_Click

End Sub

dwilliamson said:
Thank you for your response and I believe we are heading in the right
direction, pasted below is the code that I have entered and right now I get
nothing. No errors, no inspection forms open, nothing. The SITUS_ID are to
make sure the inspection form that opens is linked to the current facility.
SITUS_Facility_Type is the the dropdown list of the various facility types.

Private Sub Command55_Click()
On Error GoTo Err_Command55_Click


Dim stLinkCriteria As String
stLinkCriteria = "[SITUS_ID]=" & Me![SITUS_ID]


Select Case Me.SITUS_Facility_Type

Case "Residential"
DoCmd.OpenForm frm_inspection_residential, , , stLinkCriteria
Case "Commercial"
DoCmd.OpenForm FRM_INSPECTION, , , stLinkCriteria

End Select



Exit_Command55_Click:
Exit Sub

Err_Command55_Click:
MsgBox Err.Description
Resume Exit_Command55_Click

End Sub


akphidelt said:
Yes you can, but the only way I know how is through VBA. So you can do
something like

Right click on the button, go to build event... click on Code
Or you can go to the properties, go to events, and click on the On Click event

Type in the code

Select Case Me.Combobox

Case "Residential"
DoCmd.OpenForm "FormResidential"
Case "Commercial"
DoCmd.OpenForm "FormCommercial"

End Select

You would type in as many cases as you want... I just was showing you an
example of how it would look with a select case scenario.
 
L

Larry Kahm

Stylistic recommendations:

First, change Command54 to a name that you can recognize - preferably one
that matches the button that you are pressing. Years - or even months -
from now, you (or perhaps someone else) will wonder just what Command54
refers to...

Second, eliminate the use of underscores. Simply use "camel" case (i.e.,
SITUSFacilityType). It saves keystrokes, you would not need brackets around
the field names, and it reads slightly better.

Third, if you named your inspection forms based on what is being inspected
(e.g., frmInspectionResidential, frmInspectionCommerical), you could simply
do the following and avoid the whole select/case code chunk.:

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmInspection" & Me!SITUS_Facility_Type.Column(1)
stLinkCriteria = "[SITUS_ID]=" & Me![SITUS_ID]

DoCmd OpenForm stDocName, , , stLinkCriteria

Hope that helps!

Larry


dwilliamson said:
IT WORKS! - while waiting for a reply and doing a little more research I
found the problem and it now works. below is the code that was successful.
Thanks for all the help. that crucial part that was missing was the
.column(1) to tell the select case statement which field of the combo box
to
look in for the variable. Again thanks for the help.

Private Sub Command54_Click()
On Error GoTo Err_Command54_Click

Dim stDocName As String
Dim stLinkCriteria As String

Select Case Me!SITUS_Facility_Type.Column(1)

Case "Residential"
stDocName = "frm_inspection_residential"
Case "Commercial"
stDocName = "FRM_INSPECTION"

End Select

'stDocName = "frm_inspection_residential"

stLinkCriteria = "[SITUS_ID]=" & Me![SITUS_ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command54_Click:
Exit Sub

Err_Command54_Click:
MsgBox Err.Description
Resume Exit_Command54_Click

End Sub

dwilliamson said:
Thank you for your response and I believe we are heading in the right
direction, pasted below is the code that I have entered and right now I
get
nothing. No errors, no inspection forms open, nothing. The SITUS_ID are
to
make sure the inspection form that opens is linked to the current
facility.
SITUS_Facility_Type is the the dropdown list of the various facility
types.

Private Sub Command55_Click()
On Error GoTo Err_Command55_Click


Dim stLinkCriteria As String
stLinkCriteria = "[SITUS_ID]=" & Me![SITUS_ID]


Select Case Me.SITUS_Facility_Type

Case "Residential"
DoCmd.OpenForm frm_inspection_residential, , , stLinkCriteria
Case "Commercial"
DoCmd.OpenForm FRM_INSPECTION, , , stLinkCriteria

End Select



Exit_Command55_Click:
Exit Sub

Err_Command55_Click:
MsgBox Err.Description
Resume Exit_Command55_Click

End Sub


akphidelt said:
Yes you can, but the only way I know how is through VBA. So you can do
something like

Right click on the button, go to build event... click on Code
Or you can go to the properties, go to events, and click on the On
Click event

Type in the code

Select Case Me.Combobox

Case "Residential"
DoCmd.OpenForm "FormResidential"
Case "Commercial"
DoCmd.OpenForm "FormCommercial"

End Select

You would type in as many cases as you want... I just was showing you
an
example of how it would look with a select case scenario.


:

MS Access 2002...
I have a database with a "facility type" equal to a drop down list of
5
variables (residential, commercial, municipal, etc). I am trying to
create a
command button on this form that will open the correct inspection
form based
on the facility type. So, if residential is selected for the facility
type
and the "enter inspections" command button is clicked I want the
residential
inspection form to open up.
 
D

dwilliamson

As you can more then likely tell I am relatively new to this and I want to
thank you for taking the time and giving the advice. I will keep your
stylistic recommendations at hand for future reference.



Larry Kahm said:
Stylistic recommendations:

First, change Command54 to a name that you can recognize - preferably one
that matches the button that you are pressing. Years - or even months -
from now, you (or perhaps someone else) will wonder just what Command54
refers to...

Second, eliminate the use of underscores. Simply use "camel" case (i.e.,
SITUSFacilityType). It saves keystrokes, you would not need brackets around
the field names, and it reads slightly better.

Third, if you named your inspection forms based on what is being inspected
(e.g., frmInspectionResidential, frmInspectionCommerical), you could simply
do the following and avoid the whole select/case code chunk.:

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmInspection" & Me!SITUS_Facility_Type.Column(1)
stLinkCriteria = "[SITUS_ID]=" & Me![SITUS_ID]

DoCmd OpenForm stDocName, , , stLinkCriteria

Hope that helps!

Larry


dwilliamson said:
IT WORKS! - while waiting for a reply and doing a little more research I
found the problem and it now works. below is the code that was successful.
Thanks for all the help. that crucial part that was missing was the
.column(1) to tell the select case statement which field of the combo box
to
look in for the variable. Again thanks for the help.

Private Sub Command54_Click()
On Error GoTo Err_Command54_Click

Dim stDocName As String
Dim stLinkCriteria As String

Select Case Me!SITUS_Facility_Type.Column(1)

Case "Residential"
stDocName = "frm_inspection_residential"
Case "Commercial"
stDocName = "FRM_INSPECTION"

End Select

'stDocName = "frm_inspection_residential"

stLinkCriteria = "[SITUS_ID]=" & Me![SITUS_ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command54_Click:
Exit Sub

Err_Command54_Click:
MsgBox Err.Description
Resume Exit_Command54_Click

End Sub

dwilliamson said:
Thank you for your response and I believe we are heading in the right
direction, pasted below is the code that I have entered and right now I
get
nothing. No errors, no inspection forms open, nothing. The SITUS_ID are
to
make sure the inspection form that opens is linked to the current
facility.
SITUS_Facility_Type is the the dropdown list of the various facility
types.

Private Sub Command55_Click()
On Error GoTo Err_Command55_Click


Dim stLinkCriteria As String
stLinkCriteria = "[SITUS_ID]=" & Me![SITUS_ID]


Select Case Me.SITUS_Facility_Type

Case "Residential"
DoCmd.OpenForm frm_inspection_residential, , , stLinkCriteria
Case "Commercial"
DoCmd.OpenForm FRM_INSPECTION, , , stLinkCriteria

End Select



Exit_Command55_Click:
Exit Sub

Err_Command55_Click:
MsgBox Err.Description
Resume Exit_Command55_Click

End Sub


:

Yes you can, but the only way I know how is through VBA. So you can do
something like

Right click on the button, go to build event... click on Code
Or you can go to the properties, go to events, and click on the On
Click event

Type in the code

Select Case Me.Combobox

Case "Residential"
DoCmd.OpenForm "FormResidential"
Case "Commercial"
DoCmd.OpenForm "FormCommercial"

End Select

You would type in as many cases as you want... I just was showing you
an
example of how it would look with a select case scenario.


:

MS Access 2002...
I have a database with a "facility type" equal to a drop down list of
5
variables (residential, commercial, municipal, etc). I am trying to
create a
command button on this form that will open the correct inspection
form based
on the facility type. So, if residential is selected for the facility
type
and the "enter inspections" command button is clicked I want the
residential
inspection form to open up.
 

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

Similar Threads


Top