setfocus not working?

I have VBA code which is run in the AfterUpdate event for a text box. It 
basically checks to see if the data entered in the text box matches a 
criteria. If not, it displays an message box asking if they want to continue. 
If not, I want the text box to be re-selected so that they can change the 
value. The following is my VBA, which uses SetFocus to re-select the text 
box. But for some reason, if I try to SetFocus back on the text box, it is 
completely ignored and the form moves on to the next field. However, if I 
SetFocus on a different control it will do it just fine. So, I tried to 
SetFocus on a different control and then back to the original text box, which 
works, but instead of selecting the whole field so that the user can just 
re-type their data, the cursor moves to the end of the data so that they user 
first has to delete the previous data before re-entering the new data. If I 
SetFocus on any other text box, the whole data field is selected like I want. 
AARRRRGHHH!!! This is driving me crazy and I have not idea how to work around 
this. Can someone please help?

Here's my VBA:

Private Sub TextBox1_AfterUpdate()
Dim TextBoxData As String, Response As Integer

TextBoxData = Me!TextBox1

If TextBoxData <> "Correct Field Data" Then
        Response = MsgBox("That is not Correct Field Data. Do you want to 
continue?", vbYesNo, "Incorrect Field Data")
        If Response = vbNo Then
             Me!TextBox1.SetFocus
        End If
 End If

   
End Sub
0
Utf
11/25/2009 6:25:01 PM
access.modulesdaovba 1670 articles. 0 followers. Follow

2 Replies
1380 Views

Similar Articles

[PageSpeed] 25

try GoToControl

DoCmd.GoToControl "TextBox1"

"bigomega73" wrote:

> I have VBA code which is run in the AfterUpdate event for a text box. It 
> basically checks to see if the data entered in the text box matches a 
> criteria. If not, it displays an message box asking if they want to continue. 
> If not, I want the text box to be re-selected so that they can change the 
> value. The following is my VBA, which uses SetFocus to re-select the text 
> box. But for some reason, if I try to SetFocus back on the text box, it is 
> completely ignored and the form moves on to the next field. However, if I 
> SetFocus on a different control it will do it just fine. So, I tried to 
> SetFocus on a different control and then back to the original text box, which 
> works, but instead of selecting the whole field so that the user can just 
> re-type their data, the cursor moves to the end of the data so that they user 
> first has to delete the previous data before re-entering the new data. If I 
> SetFocus on any other text box, the whole data field is selected like I want. 
> AARRRRGHHH!!! This is driving me crazy and I have not idea how to work around 
> this. Can someone please help?
> 
> Here's my VBA:
> 
> Private Sub TextBox1_AfterUpdate()
> Dim TextBoxData As String, Response As Integer
> 
> TextBoxData = Me!TextBox1
> 
> If TextBoxData <> "Correct Field Data" Then
>         Response = MsgBox("That is not Correct Field Data. Do you want to 
> continue?", vbYesNo, "Incorrect Field Data")
>         If Response = vbNo Then
>              Me!TextBox1.SetFocus
>         End If
>  End If
> 
>    
> End Sub
0
Utf
11/25/2009 6:30:01 PM
"bigomega73" <firstscion@hotmail.com> wrote in message 
news:FEE104CF-3AF7-44C5-81B3-34D2CEA30342@microsoft.com...
>I have VBA code which is run in the AfterUpdate event for a text box. It
> basically checks to see if the data entered in the text box matches a
> criteria. If not, it displays an message box asking if they want to 
> continue.
> If not, I want the text box to be re-selected so that they can change the
> value. The following is my VBA, which uses SetFocus to re-select the text
> box. But for some reason, if I try to SetFocus back on the text box, it is
> completely ignored and the form moves on to the next field. However, if I
> SetFocus on a different control it will do it just fine. So, I tried to
> SetFocus on a different control and then back to the original text box, 
> which
> works, but instead of selecting the whole field so that the user can just
> re-type their data, the cursor moves to the end of the data so that they 
> user
> first has to delete the previous data before re-entering the new data. If 
> I
> SetFocus on any other text box, the whole data field is selected like I 
> want.
> AARRRRGHHH!!! This is driving me crazy and I have not idea how to work 
> around
> this. Can someone please help?
>
> Here's my VBA:
>
> Private Sub TextBox1_AfterUpdate()
> Dim TextBoxData As String, Response As Integer
>
> TextBoxData = Me!TextBox1
>
> If TextBoxData <> "Correct Field Data" Then
>        Response = MsgBox("That is not Correct Field Data. Do you want to
> continue?", vbYesNo, "Incorrect Field Data")
>        If Response = vbNo Then
>             Me!TextBox1.SetFocus
>        End If
> End If
>
>
> End Sub


In the AfterUpdate event, Access has already determined where the focus is 
going to go next, but hasn't yet moved the focus there.  So it does no good 
to set the focus back to Textbox1 in that event, because it will still move 
on to the next control as soon as that event is over.

For validation of the user's entry in the text box, use the control's 
BeforeUpdate event, not its AfterUpdate event.  Then cancel the event if it 
fails validation, by setting the event procedure's Cancel argument to True. 
Like this:

'------ start of code ------
Private Sub TextBox1_BeforeUpdate(Cancel As Integer)

    Dim TextBoxData As String, Response As Integer

    TextBoxData = Me!TextBox1

    If TextBoxData <> "Correct Field Data" Then

        Response = MsgBox( _
            "That is not Correct Field Data. Do you want to continue?", _
            vbYesNo, _
            "Incorrect Field Data")

        If Response = vbNo Then
            Cancel = True
        End If

    End If

End Sub
'------ end of code ------


-- 
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)

0
Dirk
11/25/2009 7:24:22 PM
Reply:

Similar Artilces:

My Office 2007 spell checker is not working.
For some reason, Office 2007 is not finding my spelling errors (in Word or PowerPoint). It is not auto-correcting, highlighting errors, or finding errors when I manually run spell check. When I go to Word options, the dialog boxes indicate that it's on and that auto-correct is also on. What's happening? ...

Help! Setfocus problem
i ave a dropdown field on the first tab. I use setfocus so that it selects a different field to stop users scrolling down and changing the selection on the load event. Problem When a user changes tab and come back to the origional tab the setfocus doesnt run as the form is already loaded. How do you get around this? This is driving me and users mad at minute...please help before i open another bottle of dark rum! Hi Brian, Check out following URL; how to fire onclick event on tab click. It may help you. http://crmrocks.net/?p=16 -- PLEASE do click on Yes or No button if this post wa...

how SIN, COS and TAN works on sql server
I ran this: declare @f float set @f = 30 select sin(@f) and got -0.988031624092862 What is this? "Roy Goldhammer" <royg@yahoo.com> wrote in message news:eRKvnY0#KHA.5476@TK2MSFTNGP06.phx.gbl... > I ran this: > > declare @f float > > set @f = 30 > > select sin(@f) > > and got -0.988031624092862 > > What is this? > > The values for SIN, COS, and TAN are in radians, not degrees. You are seeing the value of SIN(30 radians), which is correct. -- Dan "Dan" <news@worldofspack.com...

OWA Exch 2003 Not Working
I am running Windows 2003 with Exchange 2003. I am trying to acces OWA and when I do, it says that the page is under maintenance. I have tried to do http://127.0.0.1/Exchange and also http://servername/Exchange and I get the same message. Did OWA not install right. On 14 Mar, 13:01, Jeff <J...@discussions.microsoft.com> wrote: > I am running Windows 2003 with Exchange 2003. I am trying to acces OWA and > when I do, it says that the page is under maintenance. I have tried to dohttp://127.0.0.1/Exchangeand alsohttp://servername/Exchangeand I get the > same message. Did OWA no...

yes-no checkbox how to make it work
I've added the checkboxes from the control tool box and renamed them yes and no. How do I get it so when the box is clicked on the check box appears in the choice. Kevin ...

IMF apparently not working
After installing the two latest Windows Updates for server 2003 and .net framework sp1 on our exchange server, the IMF appears to have stopped working. Users are reporting a large volume of spam in their inboxes. Tried re-installing the IFM. Is it broke? Or did spammers just get really clever over the weekend? Hi Matt, If you examine the IMF performance counters, are they incrementing? Also, if you have the IMF configured to archive at the gateway, do you see any messages in the archive folder? -- Scott Schnoll This posting is provided "AS IS" with no warranties, and confe...

SFO installation not working over VPN
Hi Everyone, I have installed a laptop on a domain. I have a VPN connection setup. When I try to browse the network, I can only connect to the mscrmsnapshotshare via IP and not by host name. This is a problem as the SFO needs to connect to my crm server by name. Does anyone have any suggestions. I am using a Routfinder 660VPN. Should I do an install of Wins or an LMhosts file? Any help on this would be appreciated. thanks in advance Nic Nic, It sounds like DNS isn't working over your VPN. WINS may help, but there's probably something with the VPN that needs to be...

Connect/work offline/cancel message
In outlook 2003 connecting to SBS/Exchange 2003 server, get message: Exchange is currently in recovery mode you can connect, work offline, or cancel. This is only happening in a few computers on the network after implementing SBS 2003 with Outlook and Exchange 2003. ...

Color not working
I am operating Windows 2000, using Office Pro 2003. I am no longer able to format my cells with colors, either shading or text coloring. I have run the repair feature, but it didn't work. Bold, Underline, and similar functions still work. Please help. Thanks. CC Have a look at this: Changes to Fill Color and Fill Pattern Are Not Displayed http://support.microsoft.com/?id=320531 Biff >-----Original Message----- >I am operating Windows 2000, using Office Pro 2003. I am >no longer able to format my cells with colors, either >shading or text coloring....

Line Chart with dates in 5 day working week only
Hi, Trying to format a chart so that only the 5 working days of the week are displayed on the x axis. The source data only has the five days (e.g. 05/09/2005 down to 09/09/2005 and then on to 12/09/2005 down to 16/09/2005 etc etc) So I have missed out the weekend dates. When I create the line chart however, the weekend dates appear automatically and just show no point on the chart, therefore there is a longer line between Fridays and Mondays!! Hope this makes sense. Does anyone have any ideas on how to change this? I have tried looking at Tools-options-chart and cannot seem to turn...

CRM does not work via Internet
CRM 1.2 is not currently working via Internet. It requires a VPN connection. Is there a way to make it work on regular internet or this limitation will be addressed in the next version? Are you referring to the web client or the SFO client? The web client can be accessed publicly provided you have the appropriate ports open through your firewall (default is 80). However, there are some major security considerations to doing this. Unless you are using SSL, your company data will be being transmitted through the internet unencrypted. Due to the nature of the SFO client and it's requir...

Remote Wipe Out Work with Treo 650?
Debating whether to get the Treo 650's with the ActiveSync built in vs. the PPC-6700 (both from Sprint) for our marketing reps here. Treo's are appealing due to how cheap they are now, and with the ActiveSync looks like you can sync up with xng2k3 sp2 (which we are implementing now). ActiveSync aside, can the Treo's be remotely wiped out with the Mobility Tool in xng2k3? Or is this feature only compatible with Windows Mobile OS? Anyone? Thx! No it can't. Remote wipe will only work with Windows mobile 5.0 devices with AKU 2.0 (formerly MSFP). Treo 650 is Palm OS. -- Be...

IF formula works, need it to also rounddown
How do I use two functions in a formula? I used the IF function and am using a percent, however, I need it to also round the number down, because other cells use it and latter I am always one cent off. example: =IF(SUM(J3)>0,SUM(J3*25%),0) So if the answer is 25.49666, I want it to calculate to 25.49. Thanks, =IF(J3>0,ROUNDDOWN(J3*25%,2),0) -- HTH RP (remove nothere from the email address if mailing direct) "buddyorliz" <buddyorliz@discussions.microsoft.com> wrote in message news:A584EFD4-11BE-41AF-8F06-585059782F27@microsoft.com... > How do I use two funct...

Online Quotes don't work anymore
Online quotes stopped working yesterday. I'm using MS Money 2001 standard. Any clues? There was a glitch for a bit that seems to be cleared up now... "Robert" <bob@flythrough.com> wrote in message news:069d01c357ca$e4ccc060$a301280a@phx.gbl... > Online quotes stopped working yesterday. I'm using MS > Money 2001 standard. Any clues? >-----Original Message----- >Online quotes stopped working yesterday. I'm using MS >Money 2001 standard. Any clues? >. >I have the same issue. It worked the first time but not since. Big problem for m...

How do text capture tools work?
Here are two examples of this technology. http://www.textcapture.com/en/default.html http://www.deskperience.com/textcapture/ Sounds like they will have to involve OCR, which works fine for standard fonts but probably won't work with fancy fonts. Key here is to test them try a static control with a TextOut and change the fonts and see what happens. joe On Wed, 31 Oct 2007 15:02:04 -0500, "Peter Olcott" <NoSpam@SeeScreen.com> wrote: >Here are two examples of this technology. > > http://www.textcapture.com/en/default.html > http://www.deskp...

delegate email still not working
for exch 2003 on outlook 2003 newly supporting the above, i did not set up the initial install i created a new user with ad wizard, so it created email account, mailbox, etc i opened up a mail account for the new user in outlook express and was able to receive mail in oe for the new user, then i deleted that acct in outlook express then i added that new user account to an exisiting outlook2003 already connected to another exch mailbox, in the advanced add user section, that newly added delegate user has all permissions the outlook directory tree added the new user mailbox and exch accepted...

get rid of extra spaces between paragraphs worked only once.
Changed style from Word 7 to Word 3, used help online, but still have 2 left with spaces I cannot get rid of on my last page. Got any help for me? -- Only fools and bigots prefer French over Spanish to be taught in public or private schools. In the Styles pane (Ctrl+Alt+Shift+S), right-click the style name and choose Modify from the context menu. In the Modify Style dialog box, click Format, Paragraph. Make sure that Line Spacing is what you want, and that Spacing Before and Spacing After are both set to zero. Click OK. To transfer the style definition to the attached template, d...

Autofilter on protected work book?
Autofilter works on a protected workbook, but not when it is a line in a macro, e.g.: Selection.AutoFilter Field:=1, Criteria1:="YES" It cause a macro error. This is true even if I enable 'Allow all user of the workbook to Use Autofilter'. I'm sure I've done this before and it worked, but not now. Does anyone know if this is a bug in 2003? Or a way around it? Or another way of selecting a number of rows by a single criterion (in a macro)? Good morning Muppet Does this article help? http://www.contextures.com/xlautofilter03.html#Protect HTH DominicB -- ...

Keyboard shortcut CTRL+SHIFT+I stopped working
Using Office 2003 on Win XP SP2. Recently the Keyboard shortcut CTRL+SHIFT+I stopped working for quickly switch to your Inbox. Any advice? John ...

AutoPreview works intermittently
Outlook 2002 SP2 Affected Inbox is connecting to an IMAP server AutoPreview set to 'Preview unread items' I am an IT technitian and I have a user who likes to have her unread mail items in her Inbox to use the AutoPreview feature. At one point I went to View/Current View/Customize Current View.../Other settings... and chose 'No AutoPreview' option. I recently restored the 'Preview unread items' option. Now, an email will only AutoPreview if: I manually mark a read email as unread (right clicking on email and choosing 'Mark As Unread') or: right clic...

Multiple Sales Transaction for Same Work Order
I am in the process of trying to create a store level report by department, catagory, and item of the moneys received in total by both deposit on work orders and on direct sales that are not work orders. We require a 100% deposit (of a single tender type) on work orders. I then need to break this deposit down by department, catagory and item. Then I must add that to the same break down for direct sales. Thereby getting a total of all moneys received during a specified period for the store across all registers. So basically I am trying to figure out the data structure and org...

my vista media player stoped working!!
I can not find a download fix that works do I have to reinstall vista if so that sucks bad On Sun, 21 Mar 2010 10:29:01 -0700, mainman <mainman@discussions.microsoft.com> wrote: >I can not find a download fix that works do I have to reinstall vista if so >that sucks bad It's only going to be possible to help you if you can provide a specific description of what "stopped working" means - and step by step we could follow to guess what the problem area(s) might be. Try to isolate it for example by playing a CD (can you hear it ?), playing some music ...

Admin = form works User = form fails
This is a real stumper... I have an ubound main form named frmCreelWaste. It has a combo on it named cboWarpNo. I have a subform based on a select query against tblCreelWaste. The main and sub are linked by Parent = cboWarpNo to Child = WarpNo. In the .mdw file, there is a Group called WarpGroup, of which WarpRoom is a member, and... User WarpRoom has Open/Run permission for both forms. User WarpRoom has ReadDesign, Read, Update, Insert, Delete for tblCreelWaste. WarpGroup has Open/Run permissions for both forms. WarpGroup has ReadDesign, R...

create a letter with the data fron work sheet
i have a data sheet for the order.like people order staff lik tea,coffee...etc,i ve data including date,name,department,.....etc. when i put the data i want a letter format which picks up the data fro the sheet then i can send it to the person who made the order as confirmatino letter. like it the letter starts dear "......"(it could pick the name fro c1) also how can i create this letter? does it have to be in excel ?? help pleaseeeeeeeeeeeeeeeeeeee!!!!!!!!!!:( :( :( : -- Message posted from http://www.ExcelForum.com As answered in microsoft.public.excel and microsoft.public....

how do i get labSET to work on microsoft excel?
I cant get labSET to work in my microsoft excel i think you may have to acctivate it in the program but i am not sure. if you do i don't know how to do it. What is labSET? Is it something you use for a class? "Easyq17" <Easyq17@discussions.microsoft.com> wrote in message news:D5657704-8950-4BAB-9BE7-4008BEAF3BE8@microsoft.com... >I cant get labSET to work in my microsoft excel i think you may have to > acctivate it in the program but i am not sure. if you do i don't know how > to > do it. ...