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

access vba

ResolvedVersion 2007

Louise has attended:
Access Advanced course
Access VBA course
Excel Pivot Tables course

Access VBA

I have inherited some VBA code and am trying to put it into 1 if statement (code below). Is this possible?

' change colour background on gad score 0

If Me.GAD71ScoreTotal = 0 Then

Me.GAD71Score0.BackColor = vbBlue

ElseIf Me.GAD71ScoreTotal = 1 Then
Me.GAD71Score0.BackColor = vbWhite

ElseIf Me.GAD71ScoreTotal = 2 Then
Me.GAD71Score0.BackColor = vbWhite

ElseIf Me.GAD71ScoreTotal = 3 Then
Me.GAD71Score0.BackColor = vbWhite

End If

'change colour background on gad score 1

If Me.GAD71ScoreTotal = 1 Then

Me.GAD71Score1.BackColor = vbBlue

ElseIf Me.GAD71ScoreTotal = 0 Then
Me.GAD71Score1.BackColor = vbWhite

ElseIf Me.GAD71ScoreTotal = 2 Then
Me.GAD71Score1.BackColor = vbWhite

ElseIf Me.GAD71ScoreTotal = 3 Then
Me.GAD71Score1.BackColor = vbWhite

End If

RE: Access VBA

Hi Louise, thanks for your query. I would use the Select Case expression to achieve this. More information here:

http://www.bettersolutions.com/vba/VNN529/LA011331611.htm

Hope this helps,

Anthony

Wed 6 Jun 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:

Open A Combo Box Automatically

This is helpful if users need to enter large amounts of data. There are two ways to open ComboBoxes when they get the focus by using the tab keys.

When the ComboBox gets focus:

Press Alt + Down Arrow on the keyboard

For it to happen automatically, needs a bit of coding:

1. Add a combo box and a text box control to the form
2. Set the combo box's On Got Focus property to the following event procedure:

Private Sub ComboBoxName _GotFocus()

Me!ComboBoxName.Dropdown

End Sub


3. Open your form in Form View and use the TAB key to make sure it works.

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.1 secs.