Jumat, 08 Juli 2011

[MS_AccessPros] Re: Use both buttons and combo box to open a Forms.

 

Hi Cesar

Welcome to our group. And I'm sorry your post went unanswered for so long.

You can use the combo's AfterUpdate event to open the form based on the selection in your option frame. Here I named the option frame "fraType".

Private Sub cboState_BeforeUpdate(Cancel As Integer)
Select Case fraType
Case 1
DoCmd.OpenForm FormName:="F1", _
WherCondition:="State = '" & cboState & "'"
Case 2
DoCmd.OpenForm FormName:="F2", _
WherCondition:="State = '" & cboState & "'"
Case Else: MsgBox "Please select a Type. " _
& "Then open the dropdown and reselect the state."
End Select

End Sub

To get this code in place, open the main menu form in design view. Click on the combo so it is selected. in the properties sheet, click on the Events tab and find the On After Update line.

Click on that line and you should see a builder button (...) to the right of the line. Click it and select Event Procedure. That will open the code window to that event.

Paste my code in there, changing the names of anything I got wrong.

Now when you have an option selected the combo will know which form to open and which state to bring up.

Regards,
Bill Mosca, Founder - MS_Access_Professionals
http://www.thatlldoit.com
Microsoft Office Access MVP
https://mvp.support.microsoft.com/profile/Bill.Mosca

--- In MS_Access_Professionals@yahoogroups.com, cesarmzp89 <no_reply@...> wrote:
>
> Hello there!
>
> I'm using Access 2007, and I have the following forms:
>
> F1 - A form that has an analysis for TYPE A institutions for each State.
> F2 - A form that has an analysis for TYPE B institutions for each State in the Country.
> Main Menu - A form that is by default the form that opens up when I open this database.
>
> Let's say States are STATE1, STATE2, and so on.
>
> So my objective is the following:
>
> In the Main Menu, I have 2 buttons that alternate (you can only choose 1 option of those 2, the options being TYPE A and TYPE B) and a Combo Box (That displays the name of the States: STATE1, STATE2, ..., STATEn).
>
> So I want that, when you choose, for example, TYPE A and then choosing from the Combo Box a State -say, STATE1, for example- it opens F1 in the STATE1 Record.
> If I choose TYPE B, and STATE10 afterwards, it opens F2 in the STATE10 Record.
>
> I have a combo box that opens F1 in the State I choose... but I don't know how to tell it to open F2 or F1 depending on the Value of the buttons that alternate. Is that possible? Or is there any way of doing this another way?
>
> I appreciate the help.
> Thank you for your time and have a great day!
>
> Cesar
>

__._,_.___
.

__,_._,___

Tidak ada komentar:

Posting Komentar