473,466 Members | 1,397 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Control SetFocus

64 New Member
I have a form for entering new aircraft in a database. The first box is for the aircraft registration number. I have afterupdate code to check to see if the new number is already used. I am using a dcount method to check the tblAircraft for the number. Could use a dlookup as well. That's not the issue. I am missing something basic here.

When the user enters a number that is already in use, it fires a message box with the warning that the number is already being used. The idea then is to reset the focus to the orginal txtRegNumber txt box to try again. the user will probably use the [enter] key to close the message box. However, the ctl.setfocus part of the code seems to have no effect and the cursor ends up in the next txtbox. I am missing something because I have this same problems in several areas.

v.b.
Expand|Select|Wrap|Line Numbers
  1. 1.  Private Sub txtRegNum_AfterUpdate()
  2. 2.      Dim ctl As Control
  3. 3.       Dim varRegNum As Variant
  4. 4.        Set ctl = Me!txtRegNum
  5. 5.        varRegNum = DCount("[RegNum]", "tblAircraft", "[RegNum] = [txtRegNum]")
  6. 6.  MsgBox ("varRegNum = " & varRegNum)  ' for my program tracking purposes
  7. 7.            If varRegNum > 0 Then
  8. 8.                MsgBox ("THIS REGISTRATION NUMBER IS ALREADY IN USE.")
  9. 9.                DoCmd.CancelEvent
  10. 10.                ctl.SetFocus
  11. 11.            Else
  12. 12                Exit Sub
  13. 13.            End If
  14. 14.        Set ctl = Nothing
  15. 15.  End Sub
Thanks

-Tom
Dec 13 '07 #1
2 3434
Nathan H
104 New Member
I have a form for entering new aircraft in a database. The first box is for the aircraft registration number. I have afterupdate code to check to see if the new number is already used. I am using a dcount method to check the tblAircraft for the number. Could use a dlookup as well. That's not the issue. I am missing something basic here.

When the user enters a number that is already in use, it fires a message box with the warning that the number is already being used. The idea then is to reset the focus to the orginal txtRegNumber txt box to try again. the user will probably use the [enter] key to close the message box. However, the ctl.setfocus part of the code seems to have no effect and the cursor ends up in the next txtbox. I am missing something because I have this same problems in several areas.

v.b.
Expand|Select|Wrap|Line Numbers
  1. 1.  Private Sub txtRegNum_AfterUpdate()
  2. 2.      Dim ctl As Control
  3. 3.       Dim varRegNum As Variant
  4. 4.        Set ctl = Me!txtRegNum
  5. 5.        varRegNum = DCount("[RegNum]", "tblAircraft", "[RegNum] = [txtRegNum]")
  6. 6.  MsgBox ("varRegNum = " & varRegNum)  ' for my program tracking purposes
  7. 7.            If varRegNum > 0 Then
  8. 8.                MsgBox ("THIS REGISTRATION NUMBER IS ALREADY IN USE.")
  9. 9.                DoCmd.CancelEvent
  10. 10.                ctl.SetFocus
  11. 11.            Else
  12. 12                Exit Sub
  13. 13.            End If
  14. 14.        Set ctl = Nothing
  15. 15.  End Sub
Thanks

-Tom

Have you tried DoCmd.GoToControl "Me!txtRegNum" rather than ctl.SetFocus
Dec 13 '07 #2
missinglinq
3,532 Recognized Expert Specialist
There are a number of events where focus is kind of "in between!" The secret is to set focus to any other control (the next textbox will do) then set code back to the target textbox!

Or you could probably do it in the BeforeUpdate event of the textbox then use Cancel = True to send the cursor back to the textbox.

Linq ;0)>
Dec 14 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Colleyville Alan | last post by:
I have 2 command buttons on a form. I want the first one to be enabled and the second one to be disabled when the form is opened. That works fine. Then, after the user has pressed the first...
2
by: Lyn | last post by:
Hi, I have a text control on a form which is bound to table field StartDate which is in Date format. When updating the table record via the form, any data entered into the StartDate control is...
3
by: Not Me | last post by:
Hi, Just trying to get my head around tab controls, is there anywhere which would describe the structure of how they work? I seem to be ok so far, being able to check which page I'm on etc......
2
by: bill | last post by:
I have the following user control in my project simply for setting focus to a control: Public Class SetFocus Inherits System.Web.UI.UserControl
1
by: reidarT | last post by:
I have a webform and found some code where I understand some of it, but not all The code is as follows public static void SetFocus(Control control) { StringBuilder sb = new StringBuilder(); ...
1
by: Haobing | last post by:
I embeded an flash activex control to a wxPanel inherited class 'MyPanel' using wxPython's MakeActiveXClass method, and 'MyPanel' only has flash control ;But when then dialog init,the focus is not...
1
by: clickon | last post by:
For testing purposes i have got a 2 step WizardControl. Eqach step contains a text box, TextBox1 and TextBox2 respectively. If i put the following code in the respective activate event handlers for...
3
ADezii
by: ADezii | last post by:
One frequently asked question at TheScripts is how to set focus/make active a specific Tab on a Tab Control other than clicking on it. Before I provide the answer, I feel as though a little summary...
4
ADezii
by: ADezii | last post by:
One frequently asked question at TheScripts is how to set focus/make active a specific Tab on a Tab Control other than clicking on it. Before I provide the answer, I feel as though a little summary...
1
by: veteranwebdesign | last post by:
Hello, I have a main form. I want forms to open in a subform control box. What is the code for the option group to open the subforms in the control box. I didn't create subforms, I created...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.