LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 470
Default Explanation of code

I posted a question last month for a problem I was having with Setfocus. The
answer I got was something I had not seen before. I am teaching myself VBA
as I go along. I would appreciate it if someone could explain what the code
is doing so I can better understand it.

The problem I was having is when a user would enter an incorrect value in a
textbox, I would display a msg for incorrect entry. I would then execute the
following:

Textbox1 = ""
Textbox1.Setfocus 'to allow user to reenter correct value.

Problem is that the next textbox on userform received the setfocus. If you
need to see my code, let me know. Below is the answer I received.

***THIS IS RESPONSE TO MY QUESTION****
Enter Event of any Control Object occurs before a control actually receives
the focus from a control on the same form. Exit occurs immediately before a
control loses the focus to another control on the same form.

So a possible solution to your problem might be something like this:

Place all code behind your form with this line €śDim MyCancel As Boolean€ť at
the top outside any procedure.

Dim MyCancel As Boolean

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Cancel = MyCancel
MyCancel = False
End Sub

Replace the code Textbox1="" and Textbox1.Setfocus with:
MyCancel = True
TextBox1 = vbNullString

My questions concerning the new code I was given is this:
1) I did not know you could place code outside a subroutine. In this case,
Dim MyCancel As Boolean is by itself. What does this do?

2) What is the macro for Cancel = Mycancel doing?

3) What is being triggered with MyCancel = True?

4) Isn't Textbox1 = "" the same as Textbox1 = vbNullString?

I appreciate any help in explaning this code and what is going on.

Thanks,
Les
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Progress bar & explanation of code M1kehailu Excel Programming 1 March 4th 09 12:25 AM
Need explanation of code please glensfallslady Excel Programming 1 November 1st 06 08:33 PM
Explanation needed for CopyAllModules code davidm Excel Programming 5 July 13th 05 10:21 PM
Explanation of code Matt Excel Programming 3 January 15th 04 12:12 PM
Explanation of code marksuza Excel Programming 2 November 21st 03 11:45 AM


All times are GMT +1. The time now is 09:49 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"