Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Microsoft Access , End Sub Expected

Posted on 2013-11-20
2
Medium Priority
?
350 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 21

Accepted Solution

by:
Boyd (HiTechCoach) Trimmell, Microsoft Access MVP earned 2000 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
With its various features, Office 365 can not only help you with your day-to-day business tasks, it can also do wonders for your marketing campaign.
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…
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.

610 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