Solved

Microsoft Access , End Sub Expected

Posted on 2013-11-20
2
340 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

867 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

21 Experts available now in Live!

Get 1:1 Help Now