Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-07-2015, 08:30 AM
orozvik@yahoo.com orozvik@yahoo.com is offline UserForm textbox exit event activated with navigation buttons...why?  help? Windows 7 64bit UserForm textbox exit event activated with navigation buttons...why?  help? Office 2010 64bit
Novice
UserForm textbox exit event activated with navigation buttons...why?  help?
 
Join Date: Apr 2015
Posts: 8
orozvik@yahoo.com is on a distinguished road
Unhappy UserForm textbox exit event activated with navigation buttons...why? help?

HI Can anyone offer help on my invoice entry Excel User Form? here is the issue.



I have the following line of code for the cutomer number textbox in the form:
Private Sub txtBillToCust_Exit(ByVal Cancel As MSForms.ReturnBoolean)

'Checks the txtBillToCust field for a blank entry
If txtBillToCust = vbNullString Then
txtBillToCust.BackColor = &HFF&
MsgBox "Please enter the 8-digit Customer Number"
Cancel = True
End If

End Sub

This code will highlight the textbox with red color, prompt the user to enter the custmer number and finally clear the color and return the user to the text box where they can enter the customer number.

However, this code is causing issues with the First, Previous, Next, Last, Save File, Close navigation buttons....as when i click on any of these buttons, they do not function and the customer textbox continues to prompt me for the custmer number as the code above appears to continue.

My guess is that the exit event on the customer textbox is being activated whenever any of the navigation buttons are being depressed. I do not know why this is.

Does anyone know how to correct for this? do i need to add some error handling or other code to the cmdNext, cmdPrevious and other buttons? Or is there something i need to add to the customer textbox exit sub procedure listed above?

any help would be greatly appreciated as i am just dumbfounded at this time.

Thank you in advance.
Reply With Quote
  #2  
Old 05-07-2015, 12:42 PM
NoSparks NoSparks is offline UserForm textbox exit event activated with navigation buttons...why?  help? Windows 7 64bit UserForm textbox exit event activated with navigation buttons...why?  help? Office 2010 32bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 831
NoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really nice
Default

Quote:
My guess is that the exit event on the customer textbox is being activated whenever any of the navigation buttons are being depressed. I do not know why this is.
I believe the cancel=true part keeps the focus with the text box and you can't go anywhere else on your form without exiting the text box first, so as you suspect the procedure runs again. You're stuck in a loop there until the requirements of the text box are satisfied.

Personally I wouldn't do that check until just before writing the info to the spreadsheet, then I'd check everything, one after the other, in the order things get entered, and set focus to anything not acceptable, displaying a message at that point, and exiting the write sub.
Reply With Quote
  #3  
Old 05-08-2015, 02:50 AM
gmayor's Avatar
gmayor gmayor is offline UserForm textbox exit event activated with navigation buttons...why?  help? Windows 7 64bit UserForm textbox exit event activated with navigation buttons...why?  help? Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

I think I too might follow the approach suggested by NoSparks, but the following should work

Code:
Private Sub txtBillToCust_Exit(ByVal Cancel As MSForms.ReturnBoolean)
'Checks the txtBillToCust field for a blank entry
    If Not Len(txtBillToCust.Text) = 8 Then
        txtBillToCust.BackColor = &HFF&
        MsgBox "Please enter the 8-digit Customer Number"
        Cancel = True
        txtBillToCust.Text = ""
        txtBillToCust.SetFocus
        Exit Sub
    Else
        txtBillToCust.BackColor = &H80000005
    End If
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't use RTF Textbox in Userform (Word2007) dherr Word VBA 2 03-16-2015 07:50 AM
UserForm textbox exit event activated with navigation buttons...why?  help? Userform VBA Textbox Calculation MarkAn Word VBA 2 08-15-2014 06:50 AM
Hyperlink not activated by footpedal Donone PowerPoint 2 05-05-2014 04:42 AM
UserForm textbox exit event activated with navigation buttons...why?  help? Display result in textbox based on the input of another textbox scarymovie Word VBA 5 05-16-2012 07:05 PM
UserForm textbox exit event activated with navigation buttons...why?  help? Number format in Textbox on userform officeclerk Excel Programming 2 04-17-2012 01:23 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:44 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft