Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Application.EnableEvents = False


Hi everyone!

A recurring problem I am running into is userforms with a bunch of controls, each of them having a "change" event, and each of them interacting with each other.

I thought the Application.EnableEvents property would help me, but I can't get it to do what I thought it should be doing. Let's illustrate with a form that contains a textbox "TextBox1", and the following code:


Code:
Private Sub TextBox1_Change()
TextBox1.Text = "This has been changed"
End Sub
Private Sub userform_Activate()
Application.EnableEvents = False
TextBox1.Text = "Initial Text"
Application.EnableEvents = True
End Sub

What I thought this would do: when you .show the form, it starts with the "initialize" event which disables events, and so I expected the textbox to contain "Initial Text". Instead of that, the event TextBox1_change is called, in spite of the enableevents=false, and the textbox contains "This has been changed".

What am I not understanding, and/or doing wrong?

Thanks in advance!

Mathias




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Application.EnableEvents Not Seen
For some reason, the Application object is not being "seen" by my program. Any ideas why this would be happening?

Application.DisplayAlerts = False
I have the followingset up for a program

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

On Error GoTo NoTitle:
If Workbooks(XrefTitle).Worksheets("Dir").Range("D1").Value <= 1 Then
  Cancel = True
  MsgBox XrefTitle & "Can only be saved by programer.", vbCritical, XrefTitle
ElseIf Workbooks(XrefTitle).Worksheets("Dir").Range("D1").Value = 2 Then
  Workbooks(XrefTitle).Worksheets("Dir").Range("D1").Value = 1
End If
Exit Sub
NoTitle:
On Error GoTo 0
Cancel = True
MsgBox "Not able to save - aborted.", vbCritical, "Error"
End Sub

I want to supress the message about there being changes if it is the user trying to save only but if I do the following

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.DisplayAlerts = False
End Sub

 It reads it but dos not act on it. Also, how would I turn the dispay alerts back on as it is no longer automatic?

Application True False
i have included into workbook open event this code.

Private Sub Workbook_Open()

Application.Visible = False

MODIFICHE.Show

Application.DisplayAlerts = False
End Sub


But when i open these wbook with this code, and i have already have a session of excel opened, the opened session is hide..., how to show only the userform and not close the other session of excel opened?


Sal21

Application.screenupdating = False Error
I've set Application.screenupdating = false. However, my screen goes white.

Any idea how to stop this?

Application.Screenupdating = False Problem
Hello,

Application.Screenupdating is reseting True automatically and it's happening when I'm using code through a Menubar button when I calling my macro with .OnAction = "MyMacro" method of a control. When I use it from Immediate Window or with Run Command its working perfectly.

If someone know how to persist on Screenupdating = False before finishing rest of the Code. Please help me out!


Code:
Set MBarSubCtl = MBarCtl.Controls.Add(Type:=msoControlButton)
With MBarSubCtl
.Style = msoButtonIconAndCaption
.Caption = "Remove all &Numeric in Selection"
.FaceId = 11
.OnAction = "remNumbers()"
End With


Sub remNumbers()Application.EnableEvents = False
Application.ScreenUpdating = False
msgbox Application.ScreenUpdating
exSp = "RNUM"
frmPrgBar.lblStatus.Caption = "Do You want to remove all Numeric Characters (Numbers) in Selection?"
frmPrgBar.Show vbModal
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub

msgbox Application.ScreenUpdating always showing True when i run code on click of button. But from Immediate Window it's showing False which i need.






Suhel Khan

Alternative To Application.DisplayAlerts=False...?
Morning all,
I have a procedure which opens a workbook, copies various ranges of data to another workbook, then closes the source workbook.
I would like it to run without need for monitoring; however it is prompting me each time it tries to close a book asking if I want to save the data on the clipboard. I know I can get rid of it using Code:Application.DisplayAlerts=False but I am wondering if there is another method that doesn't impact on the rest of the program so much?
Would it be best perhaps to use the above code just before closing the workbook and then re-enable it afterwards?

Cheers,

Matt

Using HPageBreaks.Location.Row With Application.ScenUpdating=False
I am attempting to check a certain condition at the location of each horizontal page break in the active worksheet. However, because I have application.screenupdating =false, I get Run Time Error '9': Subscript out of Range.

I determined that the problem occured because the active cell was abouve the horizontal page break referred to by the HPageBreaks index and stuck in the following line before the check:

Range("a1").SpecialCells(xlCellTypeLastCell).Select

Yet the problem still occurs. Microsoft Knowledge Base Article #210663 says this problem will occur no matter what if
application.screenupdating = false.

Does anyone have a suggestion as to how I might get around this issue?

Thank you very much for any assistance.

Your Opinion Please .Enabled = False VS .Visible = False ? What Is Better?
I have an application that has the option of locking the workstation, however this feature is not available for Win95 machines. Should I .enabled = false or .visible = false in the toolbar and menu on Win95 machines?

This is basically a question on taste and opinion

False Key
Hi

SendKeys HdSt = "fjols", True

This line give me false, why )

If ((3 And 4) = False) Then
I am so confused!

Please explain why the following if statement is FALSE?

If (3 And 4) Then
msgbox ("True") 'will not come here and why?
else
msgbox ("False") 'Will come here always
end if

Thanks

Why Is This False?
If I use this code it comes out false. Why?

(0.0087 * 100) = 0.87

If I encapsulate each side of the equation with Val() it comes out true.

Is it something to do with a floating decimal point?

Help

EOF Always False
Hello,
I am using ADO to access a Microsoft Access 2000 database. I can traverse the entire recordset, but eof is never set to true. Someone posted a similar problem with ADO.NET.

Any suggestions?

Moving A From = False
ow can i limit the user from draging a form....i have a midiform and i have a toolbar on the left...how can i have it locked from being moved?
thanks-tim

True And False: Are They Mad??
Hello,

suppose to write this very simple application:


Code:
MsgBox False
MsgBox True

Now I run it into my VB6 I see first a dialog box which displays "True" followed by "False".
Now I compile it and run the .exe. I see first a dialog box which displays "Vero" followed by "Falso". "Vero" and "Falso" are the italian equivalent of True and False.

Since I use to populate the results of boolean ( ) functions directly into some sql string, this sql results to be incorrect because the sql engine doesn't recognize the string "Vero" or "Falso" where was expecting a real boolean value.

Any one has as clue for this strange behavior? On my same pc, a about two weeks ago and since two years I never got this problem and now!!!

My os is W2K in EN but Internation settings are for Italy like last 4 years!

Please...i'm getting crazy

Cmd.visible = False
Hi
Let say i have 20 Cmd and in the form load i want all of them be False is there is any easy code to write instade of write them all

other Q

i also have 8 Timer's and in each Timer there is a Long Code is there any way to make each Timer as Function and i can call it any Time i need it

Jamal

Enabled = False
Hi is their a way when a text box is disabled (e.g, txtNames.Enabled = False) can you change the colour of the text.

At present mine always turn to a dull grey!!

If not is their any way around this.

Thanks

Showintaskbar=false But It's Still There! :(
Hi!
I got my form with showintaskbar=false but I can see it there! its in the taskbar, how can I show and hide it from taksbar at runtime?
Tnx

True Or False
vb Code:
Dim ret As Boolean' some other coderet = FtpPutFile(server, fname, fname, FTP_TRANSFER_TYPE_BINARY, 0)If Not ret Then myip = ""' more code  

when i declare ret like this the myip = "" runs everytime regardless of whether ret is true or false
if i don't declare ret and leave it to vb to cast it as a variant then ret will still return true or false and the if statement runs correctly

what logic am i missing about declaring ret?

Visible=false
what's wrong with the code below?

VB Code:
Private Sub Timer1_Timer()Label1.Left = Label1.Left + 100If Label1.Left = 300 ThenIf Label1.Left >= Text1.Left Then Text1.Visible = FalseIf Label1.Left >= Text2.Left Then Text2.Visible = FalseIf Label1.Left >= Text3.Left Then Text3.Visible = False Label1.Left = 10Label1.Top = Label1.Top + 50End IfIf Label1.Top = 200 Then Timer1.Enabled = FalseEnd Sub

Not True Or False, But Nothing
When VB first starts all boolean variables are nothing (ie not True and not False)

how do i set a boolean variable to nothing

ILMV

False E-Mail
My freind needs to send an attachment to an e-mail Word.doc to his boss of work he should have completed weeks ago.

How would it be possible to send a bogus file that is totaly unreadable and wont open up on word or alternativly open up as the word doc and show binary code or somthing like that?

This is only to give him one more day to complete the work

Any help would be greatful


spud

.ControlBox = False
Someone want to explain to me why this is not allowed at runtime?


Code:
Me.ControlBox = False


Why shouldn't i be allowed to remove the control box? Doesn't make any sense.

Anyone have any ideas how i might be able to overcome this?

Set Function To False
I need to know Set Function Rebate to False.
I have tried below code but it did not work.

Each time i press undo button. It prompt me,
Gross Is Missing before perform another function

How am i suppose to avoid this?


VB Code:
Public Function Rebate(FormName As Form)If FormName.txtGross = "" ThenMsgBox "Gross  Is Missing", vbCritical, "Data Missing"Exit FunctionElseFormName.txtrebateamt = CDbl(FormName.mskrebate) * CDbl(FormName.txtGross) / 100Exit FunctionEnd IfEnd Function



VB Code:
Private Sub cmdUndo_Click()If ClearAll(FrmPoliCreate) ThenRebate FrmPoliCreate = False ' did not work as well'rebate(Frmpoli Create) = false ' did not work as wellEnd IfcmdUndo.Enabled = FalseEnd Sub

ECHO(FALSE) In VBA
Can anyone tell me what equivalent of ECHO(FALSE) in Excel 4 macro language is in VBA.
Thanks
Mick

Locked = False
I have a program that has 200 items on the form, they being textboxes. cboboxes etc.. I have set all them as locked = false, as I don't want anyone to change the values in the boxes until an add button, or edit button is pressed.
In my cmdAdd procedure I have the following code:

txtOne.Locked = False
txtTwo.Locked = False
txtThree.Locked = False etc...

Is there a one line of code I can use , instead of writing all this code in. I know I can copy and paste.

I have seen Set_All_Locks somewhere, I don't know if is VB code proper or someone's own.

Thanks

Enabled = False
Hello,

Is it possible to change the color of a font when I set its enabled property to False?


Thanks.


Deju

For I = 1 To 300 Optionbutton(i) = False Next???
How do I get this working when I have a couple of hundred optionboxes?

Can anyone help??

MAPISEND FALSE
I have a little program that is to send emails with attachment to an email address. The MAPIMessage and MAPISession code work great and will send out emails to the identified addresses. M issue is when I use the program with "send false" I expect tha Outlook Express will send without using the interface. This i great but before it sends the email, OE produces a pop-up bo alerting me that a program is attempting to send the followin email message on my behalf, prompting "Would you like to sen the message? Send or not.. this is on a box running Windows X and defeats the whole purpose of being able to send without th user interface. Have I missed some value in my code to avoi this troublesome pop-up?

Help is appreciated.

HideSelection = False
ITtoolbox Portal for Visual Basic - http://visualbasic.ittoolbox.com/

Greetings,

Old programmer here, new to VB and to this list. Developing my first VB
project, getting my feet wet...

When I set HideSelection = False, I expect text box text to remain in
selected color under all conditions, but when I set Locked = True or Enabled
= False, colors are grayed out, which is not what I need.

Any enlightenment greatly appreciated. Thanks in advance. Happy Monday!

...Ralph Lynch



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~

Using True Or False
I am sorry that this is long but i need your help!!
       Ok, I have no clue what i am doing wrong. My first form works but my second one doesnt. See, i am programming a multiple choice quiz. I am using option buttons for the choices. When you select the answer you want it will tel you if you are correct or wrong. Then after 3 seconds it will go to the next question with is on the second form. Once you click on the command button that is named EnterAnswer it will bring you to the next question/form. I can get to the second question but on the second question, it wont even tell me if i am right or wrong. Here is the code for the command button that will bring you to the second question:
Code:
Private Sub Cammand1_Click()
Select Case True
Case Option1.Value = True
Label2 = "Correct!"
Timer1.Enabled = True
EnterAnswer.Enabled = False
Case Option2.Value = False
Label2 = "Sorry Wrong Answer!"
Timer1.Enabled = True
EnterAnswer.Enabled = False
Case Option3.Value = False
Label2 = "Sorry Wrong Answer!"
Timer1.Enabled = True
EnterAnswer.Enabled = False
End Select
End Sub

And it works... it goes to question2. The code for the command button that leads you to question 3 is:
Code:
Private Sub Command1_Click()
Select Case True
Case Option1.Value = False
Label4 = "Sorry Wrong Answer!"
Timer2.Enabled
EnterAnswer2.Enabled = False
Case Option2.Value = True
Label4 = "Correct!"
Timer2.Enabled = True
Case Option3.Value = False
Label4 = "Sorry Wrong Answer!"
Timer2.Enabled = True
EnterAnswer2.Enabled = False
End Select
End Sub
EnterAnswer2 = False

AND IT DOESN'T WORK!!! I dont know why! They Are both exactly the same and i cant find a single problem!! When i click on the command it doesn't even do ANYTHING!!!!! Any ways, i am sorry that this was long but i despretally need help!!!

Set MIDChild = False At Runtime
i am trying to make an irc style chat client

the problem i have is by default i laod the room windows as MDI Children.

i am wanting to know how i can change the forms mdi state at run time...

so i can set the mdichild = true or false at runetime

can someone please help me ?

String To Represent False
I am using a formula for a cell and the formula is the syntax of If(cell#, true, false) . If the cell comes back false I want to display a string. I am trying: =If(H28, (my formula), "Error") and I am gettin a syntax error. How can I make the false represent a string?

Even I Set Visible To True But Still Is FALSE
Anyone can help me solve???

Run-time error '5':
Invalid procedure call or argument

the error occur at :
txtStk(2).SetFocus

even i set below statement before the error statement but still same:
txtStk(2).Visible = True

in immediate window i type ?txtStk(2).Visible but it show False even i set it to true.

WHY???
Edit by Moderator:

Quote:




Anyoen can HEP!!!! URGENT!!! even i set visible to true but still is FALSE




Please review this link: http://www.xtremevbtalk.com/showpost...0&postcount=11

Thank you.

How To Make Many Optionbutton False
I placed many optionbuttun on sheet

I want to do this code to include all optionbutton
optionbutton1.value= false

another thing where can I put this code to work when I run (open) my file (exl)

IF Function W/true && False
Excel 97-2000

I need to compare 2 conditions, do a calculation if True or if false print the text "--". The calculation works fine, but I canNOT get a false result to print. Here is the the code (excluding "--":

=IF(B4>999;B4<5000)*($Sheet3.B13*D3)*B4

If B4 is more than 999 and less than 5000 it will calculate. If B4 is not in the 999 - 5,000 range it returns 0 (zero); with =IF(B4>999;B4<5000) it returns false.

How do I adjust it so a false prints "--"?

TIA,

Bob

Code Gets Executed Even If The Value Is False ??
Hello,
Here is a sample of my code...


Code:
Dim IP(0 To 1000) As String

For Y = 0 to wskServer.Ubound
If wskServer(Y).State = 8
wskServer(Y).Close
IP(Y) = ""
Unload wskServer(Y)
DoEvents
End If
Next
...
For I = 1 to wskServer.Ubound
If IP(I) <> "" Then
...
End If
Next
Now the problem is that the IP(I) = "" BUT the code gets executed anyway...

Anyway to solve this ?

Thanks!

IF + 2 Conditions + AND + Exit If First Is False
Hello,

sorry for that subject - The actual question is a lot easier than to describe it in one line.
The question results from a nice feature I learned programming JAVA:
If you have an if-clause with two AND-conditions (e.g. if ((a == b) && (a != 1)) ) then JAVA will stop evaluating the conditions as soon as it notices that "a" does not equal "b".
The same works for OR-conditions when JAVA finds the first comparison to return true.
What would I need this for?
Well, when I work with databases e.g. I have to make a difference between NULL and "", because NULL can not be converted to any data-type.
Let's say I would like to compare a database text-field containing a date (I know, misconception, it's just an example) with 2003/01/27. First I need to check if the database actually contains a value, then convert it to date and compare:
if ((Not IsNull(rsData.fields("datefield"))) And (CDate(rsData.fields("datefield") = date_2003_01_27)) then ...

In the past I had to accept, that this statement throws an exception if datefield contains NULL, because VB does not exit the IF although the first part is allready false - Then, of course, CDate tries to convert a NULL-value which it can't.
Is there any tweak I can use as a work-around except reading the database-fields with default-values?

Thanx !

Rouven

FlexGrid1.Enabled = False
Hi

Q

How to set only the First Row 2 be Ebabled False

If i use this code it return all the Row's to be False

Code

FlexGrid1.Enabled = False

Jamal

Visible=false Not Working
Hi:

I'm using the following code to pause processing for 15 seconds and to display a message and a count on my form to tell the user what's going on and how long of a wait is left:

Label4.Visible = True ' show label on form
Label4.Refresh
interval = 15 ' set time to wait
Text3 = interval ' write time left to form
Text3.Visible = True
Text3.Refresh
sinTime = Timer ' initialize (seconds since midnight)
For i = 1 To interval
Do Until Timer - 1 > sinTime ' allow ~ 1 sec to pass
Loop
sinTime = sinTime + 1 ' set for next pass
Text3 = Text3 - 1 ' adjust time left
Text3.Refresh ' insure it shows on form
Next i
' done pausing - clean up and continue processing
Label4.Visible = False ' take label off form
Label4.Refresh
Text3.Visible = False ' take time left off form
Text3.Refresh

It works OK, except the message and count doesn't disappear from my form when the .visible=false and .refresh are executed at the end.

Any ideas why not?

True / False Values
Hello!

As far as I know, C stores False as 0 and True as 1. How about VB?

Set Field Values To False
How do I set the field values to False using Alter Table? I am using VB6 with MS Access DB.

The following gives me an error:

-2147217900,"[Microsoft][ODBC Microsoft Access Driver] Syntax error in CONSTRAINT clause.","This error created on:",#2006-01-18 08:01:08#



Code:
Call CreateConnection(objConn)
objConn.Execute "ALTER TABLE Documents ADD n_wavBol TEXT(50) CONSTRAINT n_wavBol_default DEFAULT False"
Call CloseConnection(objConn)

Docmd.Setwarnings False
If i use form (by itself) in the following manner and generate a primary key violation, the standard Access error message is NOT displayed (as it should not) and the Error Handler changes the invoice to "NEW INVOICE". Everything works fine!

Private Sub Command22_Click()

On Error GoTo Err_Command22_Click

DoCmd.SetWarnings False
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70


Exit_Command22_Click:
Exit Sub

Err_Command22_Click:
InvNo = "NEWINVOICE"
Resume Exit_Command22_Click

End Sub

But when the form in question is a SUBFORM....no matter what I do, when there is a key violation, the standard Access message comes on, so it appears that the docmd.setwarnings False line does not work. Please help.

YES/NO Display As True/false
Greetings:

In use Access 2000, ADO 2.7, VB6; I have the following scenario: I have a field defined as yes/no, I create a recordset and display it using MSFlexgrid.

The fields display as true, false depending on their content. What I would like to happen is that they display as YES or NO. I don't want to update the datebase, just display yes or no.

What I tried to do is before passing the record set to the grid, was to loop thru the recordset, testing for true/false and depending on the content move "YES" to the field if true else "NO" if false.

That obviously did not work: I get an error message:

-2147217887; Source: Microsoft Cursor Engine;
Multiple-step operation generated errors. Check each status value.

Can someone shed some light on how I would go about achieving my goal of "YES" or "NO" displayed in the grid?


I thank you guys in advance for your help

Donald

As follows the code I tried:


Code:
adoVehiclesRs.MoveFirst
Do While Not adoVehiclesRs.EOF

If (adoVehiclesRs.Fields("AllowSmoking") = True) Then
adoVehiclesRs.Fields("AllowSmoking") = "Yes"
Else
adoVehiclesRs.Fields("AllowSmoking") = "No"
End If

adoVehiclesRs.MoveNext
Loop

MmcAudio.Enabled = False?
I need to make mmcAudio stop playing the audio sequence when "Form2" is Form2.Enabled = False. Yes, I know that is should stop playing when that is executed, but it isn't stopping. Infact it is still playing the sequence throughout the whole project after I have finished with it.

However I want it to only play when "Form2.Visible = True" and "Form2.Enabled = True".

ZwUnmapViewOfSection? False Positive?
I'm trying to create a program using the API:

Code:
Private Declare Function ZwUnmapViewOfSection Lib "ntdll.dll" (ByVal hProcess As Long, ByVal BaseAddress As Long) As Long


But, if I put the declaration in my code, my antivirus software keeps calling it a "HEUR/Malware", even if I don't call it. I was planning on comercially releasing the software, but I don't want it to be detected. Is there any other way then using a software protector such as "software passport armadillo".

Thanks.

Enabled=true/false
I have a timer and when it is counting i want a button to be disabled but when the timer stops i want the buttons to be enabled i was using the following code which disabled the button but then doesnt enable it once the timer stops. The code is
vb Code:
Private Sub Command1_Click()If Timer5.Enabled = True ThenCommand1.Enabled = FalseElseCommand1.Enabled = TrueDim i As Long    For i = 0 To 5        If Picture1(i).Visible And Picture2(i).Visible Then            Label3.Caption = Val(Label3.Caption) + 1            Exit For        End If    Next i    End IfEnd Sub    Private Sub Timer5_Timer()Picture3.Visible = FalsePicture4.Visible = FalseTimer5.Enabled = FalseEnd Sub



What is wrong with this code. Also can soemone tell me the code for when the button is clicked it cant be clicked again. Until something happens.

Thanks

Jamie

PortOpen = False On EXIT ?
Hello,

My program is running well , bet when I exit my program and go to a other program that need the comport I have just used , the other program tell me "Port in use"

I add a button .PortOpen = False , now it work , but I would like that this happens when I press the CLOSE or EXIT button from my form.

Any "On_Exit" or "On_Close" Command ?

Best Regards,
Didier.


VB Code:
ublic Function CommSelect(x As Integer) As StringWith ctlMSComm 'configuration du portIf .PortOpen = True Then .PortOpen = False.CommPort = x 'On utilise le port COM1:.Handshaking = 0.RTSEnable = 0.Settings = "9600,n,8,1".SThreshold = 0.InBufferCount = 0.InBufferSize = 1.OutBufferSize = 1.InputMode = 0.InputLen = 1.RThreshold = 1.SThreshold = 1On Error GoTo Comms_Error.PortOpen = TrueExit FunctionComms_Error:    If Err = 8002 Then    ' Port already open        MsgBox "Sorry, No Com" & x    End If    Resume NextEnd WithEnd Function

UseMnemonic In MENUS To FALSE ?
Hello,

Is there a way to display the & character on a menu item.. just as if you could disable this on a label by changing the UseMnemonic option.... is this possible on a menu item?

Using Objects [False Alarm]
I have a small number of checkboxes (not forming an array) chk1, chk2, chk3 and chk4. Each one of these must be moved to a specific place on the form and I would like to use a dummy checkbox for the matter, but the code below doesn't work (produces an error):

VB Code:
Dim ch As CheckBox'N (1 -> 4) is selected by the userSelect case N    Case 1        Set ch = chk1    Case 2        Set ch = chk2    Case 3        Set ch = chk3    Case 4        Set ch = chk4End Select'offset has already been initializedch.Left = offset(N)

Copyright 2005-08 www.BigResource.com, All rights reserved