[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

move through controls in form

Posted on 2011-10-18
4
Medium Priority
?
363 Views
Last Modified: 2012-05-12
Hi,
How can i go through each control in form and run conditions if the control is textbox or combobox and the backcolor of the controls are #F9EDED ,my code is not working:

Private Sub Form_BeforeUpdate(Cancel As Integer)

    Dim msg As String, Style As Integer, Title As String
    Dim nl As String, ctl As Control

    nl = vbNewLine & vbNewLine

    For Each ctl In Me.Controls
      If ctl.ControlType = acTextBox or acComboBox Then
        If ctl.backcolor="#F9EDED" And Trim(ctl & "") = "" Then
         msg = "Data Required for '" & ctl.Name & "' field!" & nl & _
               "You can't save this record until this data is provided!" & nl & _
               "Enter the data and try again . . . "
          Style = vbCritical + vbOKOnly
          Title = "Required Data..."
          MsgBox msg, Style, Title
          ctl.SetFocus
          Cancel = True
          Exit For
        End If
      End If
    Next

End Sub

Open in new window

0
Comment
Question by:drtopserv
  • 2
3 Comments
 

Author Comment

by:drtopserv
ID: 36984795
i think i have solved the problem myself:}
thnx anyway:}
0
 

Accepted Solution

by:
drtopserv earned 0 total points
ID: 36984994
Private Sub Form_BeforeUpdate(Cancel As Integer)

    Dim msg As String, Style As Integer, Title As String
    Dim nl As String, ctl As Control

    nl = vbNewLine & vbNewLine

    For Each ctl In Me.Controls
      If ctl.ControlType = acTextBox or ctl.ControlType = acComboBox Then
        If ctl.backcolor=RGB(249,237,237) And Trim(ctl & "") = "" Then
         msg = "Data Required for '" & ctl.Name & "' field!" & nl & _
               "You can't save this record until this data is provided!" & nl & _
               "Enter the data and try again . . . "
          Style = vbCritical + vbOKOnly
          Title = "Required Data..."
          MsgBox msg, Style, Title
          ctl.SetFocus
          Cancel = True
          Exit For
        End If
      End If
    Next

End Sub
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 36985066
You can use this notation if you know the colour in hex

If ctl.backcolor=&HF9EDED And Trim(ctl & "") = "" Then

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

873 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