98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Access VBA Training and help » Forms
Forms
Resolved · Medium Priority · Version 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 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
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Access tip:Calculating The Difference Between DatesIf you wish to calculate the time between two date fields, this can be done in a number of ways: |