Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

forms

ResolvedVersion 2010

Ross has attended:
Excel VBA Intro Intermediate course

Forms

I have created a form

Sub Selectionlist()

Account.AddItem "Net Income1"
Account.AddItem "cash1"
Account.AddItem "Net Income1"
Account.AddItem "Depreciation & Amortisation"
Account.AddItem "Intercompany Interest"
Account.AddItem "Minority interest"
End Sub

Then i have addeded a command button

what i would like to do is

once they have selected one of the items in the drop down on fhe form do a function. say

if "selections list above" = "Net Income1" then
Range("a1:b2").select.
End If


The problem i have is cant get the macro to refer to the form. I need to name the selection in the form somehow?

Also how would the command button know what macro to run(will it just run the routine sitting behind the form? if that the case i guess i could call other macros into the routine?)

RE: Forms

Hi Ross,

Thank you for your question.

The value you talk about are they displayed in Text Boxes or a combo box? If so, name the text boxes and combo box in the properties in the VBA window.

Double click into the form VBA and create a new routine. The code would be something like this:

e.g. cboTest is the name of the combo box


Private Sub cboTest_change()

Select Case Me.cboTest

Case Is = "T1"
Sheets("Sheet1").Range("a1:a5").Select

Case Is = "T2"
Sheets("Sheet1").Range("b1:b5").Select

Case Is = "T3"
Sheets("Sheet1").Range("c1:c5").Select

Case Else

Sheets("Sheet1").Range("d1:d5").Select

End Select

End sub

Add a Command button to sheet1 and right click view code. In the command button procedure type the name of the form followed by .show

e.g. MyForm.show

I hope this helps.

Regards

Simon

Fri 10 Feb 2012: Automatically marked as resolved.

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Access tip:

Closing form after a certain time period

To make a form close automatically after a certain time period, you need to assign the close function to a macro.

Save the macro and ope up the form in design view. open the Properties sheet.

In the TimerInterval property enter the length of time you want the form open for. This should be in milliseconds, so for instance if you want the form open for 5 seconds enter 5000, for an minute enter 60000.

You now need to attach your macro (to execute the Close action) to the OnTimer event property of the form.



View all Access hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.