Solved

Microsoft Access , End Sub Expected

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
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 create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
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.

821 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