?
Solved

Please ammend this code

Posted on 2003-03-05
8
Medium Priority
?
237 Views
Last Modified: 2010-05-01
Form1 contains some textboxes and comboboxes which their Tag are "T" .
in the following code i want to show a warning msgbox when i press return key if any of these controls = ""


Private Sub Form_KeyPress(KeyAscii As Integer)
Dim Ctrl As Control

If KeyAscii = 13 Then
For Each Ctrl In Controls
    If Ctrl.Tag = "T" Then
        If Ctrl = "" Then
             MsgBox "Fill this control"
        Else
            SendKeys "{Tab}"
        End If
    End If
Next Ctrl
End If

End Sub

in this code I receive many msgboxes but I need only one msgbox and after i click OK the focus stay in this blank control to fill it.

Thanx
0
Comment
Question by:GouGou
[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
8 Comments
 
LVL 5

Expert Comment

by:bob_online
ID: 8075083
Private Sub Form_KeyPress(KeyAscii As Integer)
Dim Ctrl As Control

If KeyAscii = 13 Then
For Each Ctrl In Controls
   If Ctrl.Tag = "T" Then
       If Ctrl = "" Then
            MsgBox "Fill this control"
            exit sub
       Else
           SendKeys "{Tab}"
       End If
   End If
Next Ctrl
End If

End Sub

0
 
LVL 3

Expert Comment

by:DocM
ID: 8075086
Dim Ctrl As Control

If KeyAscii = 13 Then

For Each Ctrl In Controls
   If Ctrl.Tag = "T" Then
       If Ctrl = "" Then
            MsgBox "Fill this control"
       Else
           SendKeys "{Tab}"
           Exit For
       End If
   End If
Next Ctrl
End If
0
 
LVL 5

Expert Comment

by:bob_online
ID: 8075093
I don't think you want the sendkeys "{Tab}" but am not entirely sure what you're doing.  There probably is no good reason to tab through all your controls while testing this out.  You can probably, before the exit sub I added, do ctrl.setfocus
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Expert Comment

by:Jacamar
ID: 8075454
Private Sub Form_KeyPress(KeyAscii As Integer)
Dim Ctrl As Control

If KeyAscii = 13 Then
For Each Ctrl In Controls
   If Ctrl.Tag = "T" Then
       If Ctrl = "" Then
            MsgBox "Fill this control"
            Exit for
       Else
           SendKeys "{Tab}"
       End If
   End If
Next Ctrl
End If

End Sub
0
 
LVL 11

Expert Comment

by:supunr
ID: 8075814
Private Sub Form_KeyPress(KeyAscii As Integer)
Dim Ctrl As Control

If KeyAscii = 13 Then
For Each Ctrl In Controls
   If Ctrl.Tag = "T" Then
       If Ctrl = "" Then
            MsgBox "Fill this control"
            Ctrl.SetFocus
            Exit sub
       Else
           SendKeys "{Tab}"
       End If
   End If
Next Ctrl
End If

End Sub
0
 
LVL 3

Expert Comment

by:DocM
ID: 8076046
Private Sub Form_KeyPress(KeyAscii As Integer)
Dim Ctrl As Control

If KeyAscii = 13 Then
For Each Ctrl In Controls
  If Ctrl.Tag = "T" Then
      If trim(Ctrl) = "" Then
           MsgBox "Fill this control"
           Ctrl.SetFocus
           Exit sub
      Else
          SendKeys "{Tab}"
      End If
  End If
Next Ctrl
End If

End Sub
0
 

Accepted Solution

by:
toni2002 earned 200 total points
ID: 8079071
Private Sub Form_KeyPress(KeyAscii As Integer)
Dim ctrl As Control

For Each ctrl In Controls
    If KeyAscii = 13 Then
        If ctrl.Tag = "T" Then
           If ActiveControl.Text = "" Then
                MsgBox "Fill This Control"
                KeyAscii = 0
                Exit Sub
            Else
                SendKeys "{Tab}"
                Exit For
            End If
        End If
    End If
Next

End Sub

you must define which control you are in because u use Tag for many controls
0
 
LVL 3

Expert Comment

by:DocM
ID: 8082559
The code of Toni2002 do not check all the controls with
the Tag set to "T".
It only check for the active control, even if its tag is not set to "T".
If ActiveControl.Text = "" Then
               MsgBox "Fill This Control"
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month14 days, 18 hours left to enroll

770 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