Solved

Microsoft Access , End Sub Expected

Posted on 2013-11-20
2
339 Views
Last Modified: 2013-12-02
I wrote a very basic VB program to change the color of a field upon click in. The code is as simple as below :


Private Sub Full_Name_Click()
Function SetActiveControlColour()
Dim ctl As Control

    For Each ctl In Me.Controls
        ctl.BackColor = vbWhite
    Next ctl
    Me.ActiveControl.BackColor = vbRed

End Function
End Sub

When I try to compile it, I receive an error message : End Sub Expected .
Any assistance will be very much appreciated.
0
Comment
Question by:user_expert
2 Comments
 
LVL 21

Accepted Solution

by:
Boyd (HiTechCoach) Trimmell, Microsoft Access MVP earned 500 total points
ID: 39664862
You have a function dim'ed inside a Sub.  Which one are you trying to use?

**WARNING*** You code will try to set the back color of all controls on the form including labels, etc. Is that what you really want?

Are you sure you do not want to use the On Enter event?

I think this is what you want:

Private Sub Full_Name_Click()

Call SetActiveControlColour

End Sub

Function SetActiveControlColour()

Dim ctl As Control

'* set all controls to White
    For Each ctl In Me.Controls
        ctl.BackColor = vbWhite
    Next ctl

'* Set Active Control Red

    Me.ActiveControl.BackColor = vbRed

End Function

Open in new window


Better would probably be something like this:

Function SetActiveControlColour()

Dim ctl As Control

'* set all Combo box, Text box, and List box controls to White
    For Each ctl In Me.Controls
 
        Select Case ctl.ControlType
            Case acComboBox, acListBox, acTextBox
                 ctl.BackColor = vbWhite
        End Select

    Next ctl

'* Set Active Control Red

    Me.ActiveControl.BackColor = vbRed

End Function

Open in new window

0
 

Author Comment

by:user_expert
ID: 39685969
Thank you very much theHighTechCoach. I will try it this evening and give you a feedback.
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now