Using if statement to determine which form to open

N

Nina

Hi,

I need some help with using an if stament to determine which of 3 forms I
should open. The if statement should be based on values chosen on 1 combo
box.

The combo box is :

cboco1 - which chooses the company (WM, PS or CAB) and the selection is
stored as a temp var ... =[TempVars]![CoID]

When the user clicks on the Login button it should determine which Form to
open :

There are 3 different forms one for each company.

I really appreciate your help!!
 
C

Chris

Well, I wouldn't do it that way, as you have to maintain 3x the number
of forms.

But, in the On_Click event of the Login Button,

Select Case CBOCO1
Case "WM"
DoCmd.OpenForm "frmWM"
Case "PS"
DoCmd.OpenForm "frmPS"

'Etc.


End Select


Chris
 
D

Dirk Goldgar

Nina said:
Hi,

I need some help with using an if stament to determine which of 3 forms I
should open. The if statement should be based on values chosen on 1 combo
box.

The combo box is :

cboco1 - which chooses the company (WM, PS or CAB) and the selection is
stored as a temp var ... =[TempVars]![CoID]

When the user clicks on the Login button it should determine which Form to
open :

There are 3 different forms one for each company.

I really appreciate your help!!


I don't have Access 2007 handy at the moment to test with, and I haven't yet
used TempVars for anything, but I would expect something like this to work:

Dim strFormName As String

Select Case TempVars!CoID
Case "WM" : strFormName = "FormForWM"
Case "PS" : strFormName = "FormForPS"
Case "CAB" : strFormName = "FormForCAB"
End Select

DoCmd.OpenForm strFormName
 
D

David H

Actually if you're using a comboBox or ListBox you don't need any sort of
logic. Since both controls allow for multiple columns, you can design them so
that the formName is in one of the columns and is used to open the correct
form as in.

Column 1 Column 2
frmOrders View Orders
frmReports Reports
frmCustomers View Customers

Set the .ColumnWidths property to 0", 2" to hide the first column
Set the .BoundColumn property to 1 to bind

Then in the _afterUpdate event of the comboBox add...

DoCmd.OpenForm [comboBox]

If you want to go even slicker, you could a third field that contains the
criteria used to filter the records on the form as in

Column 1 Column2 Column3
frmOrders View Orders
frmOrders Status='Pending' View New Orders

If [comboBoxname.Column(1)] = "" then
DoCmd.OpenForm [comboBox]
else
DoCmd.OpenForm [comboBox],,,,[comboBox].Column(1)
end if

Dirk Goldgar said:
Nina said:
Hi,

I need some help with using an if stament to determine which of 3 forms I
should open. The if statement should be based on values chosen on 1 combo
box.

The combo box is :

cboco1 - which chooses the company (WM, PS or CAB) and the selection is
stored as a temp var ... =[TempVars]![CoID]

When the user clicks on the Login button it should determine which Form to
open :

There are 3 different forms one for each company.

I really appreciate your help!!


I don't have Access 2007 handy at the moment to test with, and I haven't yet
used TempVars for anything, but I would expect something like this to work:

Dim strFormName As String

Select Case TempVars!CoID
Case "WM" : strFormName = "FormForWM"
Case "PS" : strFormName = "FormForPS"
Case "CAB" : strFormName = "FormForCAB"
End Select

DoCmd.OpenForm strFormName


--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)
 
D

David H

That trick is a viable alternative to using a Switchboard. My specific
variation of it is table based.
 
D

Dirk Goldgar

David H said:
Actually if you're using a comboBox or ListBox you don't need any sort of
logic. Since both controls allow for multiple columns, you can design them
so
that the formName is in one of the columns and is used to open the correct
form

Agreed, and it's what I would do.
 

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

Top