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




Lost_Focus Vs. Validate Event


If TextBox1.Value <> "a" Then Cancel = True

Ok, I don't think what I am trying to do is so complicated, but..!!

Anyhow, I have 1 form with 2 text boxes names calc1 and calc2, 2 labels which are locked from the user with
the caption of 301 and 301 and named player1 and player2, next I have a button on the form called new game.
That's it.

What I am trying to acheive is the following:

I want the form to load with focus set to calc1 - done.

I want to enter a value in calc1 - validate if it's ok (i.e. between 170 and 60), if it's valid go to calc2 - done
calc2 I want to do the same and then go back to calc1

Basically I want to go back and forth between calc1 and calc2 only - each time validating the score entered
and subtracting it from the player1 and player2 labels.

I have tried lost_focus, validate events but I can't get it work properly. If the score is invalid the lostfocus
will go to calc2 regardless- it's fine if a valid score is entered. Then I tried the validate - seems to work
but when I go back to calc1 and press tab (that's another issue I have - since I want to use the enter button
to change focus, but anyhow) it goes to the new game button....

Any ideas what is going wrong here - I really need a chart indicating the order of execution for these
events.
Any Help greatly appreciated.
Thanks




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Is There Any Application Lost_Focus Event?
Like any object. how do I know that I have lost focus from my Application.

Validate Event
I opened a new project,placed a textbox and a commandbutton on a form and throw following code.

Private Sub Text1_Validate(Cancel As Boolean)
If Val(Text1.Text) &lt; 100 Then

If MsgBox("Value is out of expected range. Do you want to keep it anyway ", vbOKCancel) = vbOK Then
Cancel = False
Else
Cancel = True
End If
End If
End Sub

When I got the msgbox and I press OK to continue, the command button has the focus but strangely when the mouse hovers on it it gets a pressed appearance as if a mousedown is in effect on the button. What do you think about it ? How can it be prevented ?

Secondly I need to set Cancel = True in the Validation event.
But only if the user wants to click a special button on the form such as "Update" but it seems that there is no way to record where you clicked before deciding to keep the focus or release it.

Validate Event
can sobody please show me how to use the _validate(cancel as boolean) event
i know i have to set the instructions under that sub but how do i use the event(for example when i click a button)

"Shibby!"

Validate Event
Accessing a database, have Insert button in a menu (Add Operation) and a Finished button that stays disabled throughout the program UNTIL all three text boxes contain valid data and aren't empty...


Code:
Private Sub txtName_Change()

If Not txtName.Text = "" Then
cmdFinished.Enabled = True
Else
cmdFinished.Enabled = False
End If

End Sub

Private Sub txtPrice_Change()

If Not txtPrice.Text = "" Then
ValidPrice
txtQuantity_Change
cmdFinished.Enabled = True
Else
cmdFinished.Enabled = False
End If

End Sub

Private Sub txtQuantity_Change()

If Not txtQuantity.Text = "" Then
ValidQuantity
cmdFinished.Enabled = True
Else
cmdFinished.Enabled = False
End If

End Sub

I would prefer to use the Validate event.... how?



Code:
Private Sub txtName_Validate(Cancel As Boolean)

If Not txtName.Text = "" Then
'cancel=false ??
cmdFinished.Enabled = True
Else
'cancel=true??
cmdFinished.Enabled = False
End If

End Sub

Private Sub txtPrice_Validate(Cancel As Boolean)

If Not txtPrice.Text = "" Then
ValidPrice
txtQuantity_Change
cmdFinished.Enabled = True
Else
cmdFinished.Enabled = False
End If

End Sub

Private Sub txtQuantity_Validate(Cancel As Boolean)

If Not txtQuantity.Text = "" Then
ValidQuantity
cmdFinished.Enabled = True
Else
cmdFinished.Enabled = False
End If

End Sub

Thanks....

Validate Event
Hi,

I'm notice that every control (built in or third party) will have this event create automatically by VB.
This event working greatly. But when i moving focus to other control using code, this event doesn't fire. Is that this control normal behaviour or something wrong?

Thanks

Validate Event (Take Two)
Hi everybody !

I have already asked the same thing here:http://www.vbforums.com/showthread.php?t=436068

Now Im back, because I dont found the solution ???

I attached with this thread, a very little project that shows my problem...Cloud you try it please ?

I have a textbox (Text1) with a validate event. If this textbox is empty it's supposed to keep the focus and it's not the case because I can go to another TAB ? Why ? Is it normal or no ?

Thanks for your help !

Validate Event
I have a text box with a validate event with some code in it. The validate event never occurs. Any ideas or similar situations? There is a keypress event as well for the same text box if that makes any difference. CausesValidation property is set to true for the text box.

I would expect that when I press the tab key the validate event would fire. This happens for all the other text boxes on the form but this particular one.

Thanks, maybe I can stop wracking my brain over this one.

Validate Event
Hello

What is Validate function ?
When it fires ? (Before GotFocus or Lostfocus etc)
How to use it ?

Thanks in advance
Farooq

Validate Event ?
I have 2 textbox in my form . ( text1 , text2 )

validate event of text1 consists of the following statement :

if msgbox("Any Message",vbyesno)=vbno then cancel=true



Now the problem is ,

if I try to go to text2 with mouse , message appears , i choose yes , focus goes

to text2 , But As if the mouse button is still in down position , which is really not.

so when I move my mouse , text in text2 gets selected as if mouse button is still in pressed state .


What is the reason of this behaviour ? Any Solutions ?

( everything is ok if uses tab to goto text2 )

Validate Event
I require a user to fill in data on a certain Textbox control...the user cannot continue unless supplying the required data....the problem is...when the user hits the close button....it never triggers...i cant unload my form....

Any ideas/work arounds....im tired of re-coding....



TIA

Validate Event
This is something weird I noticed the other day while testing our app. We have a tabstrip control (SSTab) and on each tab there is a frame which contains certain textbox and other controls.

In two of the textboxes, I wanted to allow the user to edit the value only through the press of a command button. Otherwise the textboxes had to be disabled. So I coded the form in such a way that the textboxes are disabled at the beginning. In the Click event of the command button, I enable a textbox and allow the user to enter data into it. Since after data entry I again wish to disable the textbox, I trap the Validate event of the textbox and disable the textbox in this Validate event procedure.

All was fine, until I clicked the button to edit the textbox, put some data into it and then clicked on another tab in the SSTab control. The other tab became visible, and then I returned to the earlier tab, and the textbox is still enabled!! That means the Validate event was not fired when I changed the tab.

Here is the code:


Code:
Private Sub Form_Load()
Text1.Enabled = False
End Sub

Private Sub Text1_Validate(Cancel As Integer)
Text1.Enabled = False
End Sub

Private Sub Command1_Click()
Text1.Enabled = True
Text1.SetFocus
End Sub


I need a verification of my opinion that the Validate event is not fired when I click on another tab of the SSTab control on which the textbox is placed.

Note that the Validate event does work with other controls, for e.g. when I move from Text1 to another control, say Text2, the Text1_Validate event is fired.

.

Validate Event
Hi

How do I out form a textbox when the user click a button, I have a textbox and someone buttons and want that when the user click in the CANCEL button, It ignore the validate event

How do I do It ?

thanks

Validate Event
Does anybody know how to force this event to fire (Sometimes it doesn't fire when moving focus to another control). When I exit a form, I want all the validate events to fire for all controls on that form.

Is there a way to do this anyone?

Validate() Event ?
What is the significance of Validate() event in VB? Can you please specify an example as to where this event can be used?

In the programs I have created, I have written the validations in the Change() and KeyPress() events in case of text fields and in Click() event in case of buttons. So, where does the Validate() event fit in?

Anna

Validate Event!
Could anyone help me!

I have created an activeX control (which happens to be a cut down text box) which will be displayed on an HTML form in IE5.
What I want to know is does anyone out there know how to fire the validate event (which I have mapped to the text box) from the HTML form. I have set the causes validation property to true so why won't it work?

Validate Event In OCX
Hi together

I'm writing an OCX with various edit fields. I'm using the Validate event for checking numbers etc. Everything works fine inside the VisualBasic environment.

But when the OCX is loaded by the application it's written for, there are two things I don't know to handle:

- There is no validate event when a control looses it's focus.

- There is no focus change when pressing the tab key. Only a beep is heard.

How can I fix this?

Thank you
Andreas

Validate Event
Hi
I am facing a problem using the validate event in VB6.0 . i have an abort
and and exit button which should not be validated when the focus is lost
from the text box, but the toolbar does not have a cause validate event .
please any idea for this. the mouse down event is also fired after the validate event is fired
any API calls can help..




thanks in advance
jagdish

Validate Event
Hi

I have a problem with the validate event of a textbox. When I add the textbox to a form, the validate event occurs exactly when it's supposed, to (when you try to go to another control).
But, if I put the textbox on a usercontrol, the validate event never occurs! Although the same settings are used (CausesValidation = True).
Of course I get the LostFocus, but that's too late.
Has anyone experienced this too and/or knows a sollution?
Oh, I'm using VB6 with SP2 on NT4 Server with SP4, (including option pack).

Tnx in advance


Crazy D :-)

Avoiding The Validate Event.
Good day, Is it possible to know what object that the user has clicked on during the Validate event, ie which object will get the focus next.

Thank you in advance.

Validate Event Of An Object...
Hi folks! Long time no see...

I feel stupid, but anyway: is there a way to determine what caused the Validate event of an object?

I'm checking some facts in the validate event of the TextBox, but it won't let me mark the CheckBox in the process. It's something like this (if you know what I mean...):


Code:
Private Sub chkUseCurrentDate_Click()
Text1.Text = IIf(chkUseCurrentDate, Date, "")
End Sub

Private Sub Text1_Validate(Cancel As Boolean)
If Text1.Text = "" Then Cancel = True
End Sub

I know of the way around, but it would cause me to change the whole lot of logic behind.

In Delphi there's a parrameter called Sender in the parameter list of the event, so I know what caused the event. I wonder if there's a work around here...

Forcing A Validate Event
I need the validate event to fire when the user clicks a menu after changing a textbox. I've tried setting the focus to another control while in the menu item's onclick handler but it doesn't fire the validation.

It would be so nice to have a .validate method for the text box, but in the meantime has anyone got any clever ways of causing validation.

(for complex reasons I can't use the kepressed or change events and of course the lostFocus event doesn't fire either)

Change Event Vs Validate?
Is there a way to use either Change or Validate for the follwing action?


Code:
Private Sub cboTech_[b]click[/b]()

[b] Populate[/b]
End Sub

I have the combo set to simple combo as its use will mainly serve to type in a number and populate text boxes. If the number is null I have it set to return 9999 in all boxes.

How it is set now- you need to type in your 4 digit number and arrow down to populate the other boxes.( because of the click event) Is there a way to use change event or validate so the user doesnt have to arrow down?
Id rather have them just type in 4 digits and have the boxes populate upon adding the last digit automatically.
I know change fires with the first digit.

Save On Validate Event
Hi, I want to save my data only if data changed. I already read another message in this forum that says that i must use the change property of all the controls. My problem is that I load data from database in the data_reposition event. So, juste after the form_load and form_activate event all the event click or change are fired. And i wonder if there is another event after that I can put my boolean to false before user start changing control. I save my data in the data_validate event. But I have a lot of control that are not based on the data (option button and list) so I wanna be able to know in the data_validate if there's some change in my data (text.datachanged doesn't work for option button)
Thanks

Validate Event With Menu
Hi Everybody !

Is it normal that the validate event is not fired when I click in menu ???

Thanks in advance !

Note: NEVER USE SSTAB ! I LOST 2 HOURS TO REPLACE IT BY TABSTRIP !

What's The Advantage Of 'Validate' Event?
VB Code:
'The Validate Event and the CausesValidation Property'The first enhancement that affects just about all intrinsic'ActiveX controls is the addition of the Validate event and'the CausesValidation property. Before VB6, if you had to check'to see if a word was typed properly in a TextBox, you most'likely would program the TextBox's LostFocus event handler'to see if, indeed, the user entered correct data. If they hadn't,'you could invoke the control's SetFocus method in which validation'was occurring to keep the user from proceeding. Sometimes the'logic of this programming could cause your users problems. If'they never entered the right data, they would be locked into'that one control--they couldn't even click a Help button. The'new Validate event procedure and the CausesValidation property'address this issue.'------'Listing 2.1 shows how to use the Validate event procedure to'check a TextBox's data. If users don't type the word Cherries'in the first TextBox, they can't proceed to the second TextBox.'However, because the value CausesValidation property of the'CommandButton is set to False, users can click it to help'determine the right word to enter.'------'Using the CausesValidation property'Notice the Cancel parameter on Line 1. Visual Basic provides'this parameter within the control's Validate event procedure.'If you set the value of Cancel to True (Line 7), the'program's focus won't be allowed to leave the control except'to go to other controls that have their CausesValidation'property set to False.'-------'The Validate event procedure allows you to check for correct'data while still allowing you to access other controls during'the validation process. Option Explicit Private Sub Text1_Validate(Cancel As Boolean)'Make it so that if the user does not'enter the word, "Cherries" in the TextBox'the cursor will be returned this TextBox    If Text1.Text <> "Cherries" Then        MsgBox "You cannot go on!"        Cancel = True    End IfEnd Sub Private Sub Command1_Click()    Dim strMsg As String    Dim strQuote As String    strQuote = """"'Make an instructional message    strMsg = "You must type the word," & strQuote    strMsg = strMsg & "Cherries" & strQuote & " "    strMsg = strMsg & "in the first TextBox."    MsgBox strMsg, vbInformation, "Instructions"'The reason that you can click on this'CommandButton even though the Cancel parameter'of the Validate event handler is set to True'is because the value of CauseValidation'property of this CommandButton is set to false.End Sub

Err... I don't really see the advantage of Validate event and CauseValidation property. I think we can do this using LostFocus and SetFocus events. Pls advise what's the advantage of using Validate event? Thanks

A Quick One About The Validate Event
I have the validate event of a textbox so set that if the input is wrong (not numeric) then the focus is not allowed to leave the textbox.

The nag is, if I decide to stop the program via an "exit" button, the program won't exit unless I first enter something meaningful in that textbox. What would be a clever way around?

Validate Event In Textbox
Hi all,

I am having troubles with the validate event of a textbox.

By leaving the Textbox the validate_event is supposed to show a msgbox.

My Problem is, that this mgsbox shows up twice.
Why is that? What can I do against it?

I am happy for any help!

Thnx!

Validate Event Dilema..HELP
I have a form with a text box and a comand button, now the textbox is a required field, is user tab or lost focus I'm firing a validate event with MSG, now the button is for cancel, the problem is if i run this prog and the text box has the focus, if I click cancel the error comes up, HOW can I prevent the validate event to fire if I'm clicking on cancel, if the user does not enter anything in the txt box and he wants to cancel, this msg box should not show up....how can I prevent this????

Textbox Validate Event
I've searched the forum for an answer to this but so far not had any luck.

I have a number of textboxes for which I wish to apply the same entry restrictions. Basically I only want numeric input so I wrote a little sub that will restrict accordingly - I fire this sub in the keypress event of the text boxes in question:


VB Code:
Private Sub txtTotalMonthly_KeyPress(keyascii As Integer)    RestrictTextNumeric txtTotalMonthly, keyasciiEnd Sub Private Sub RestrictTextNumeric(txtBox As TextBox, keyascii As Integer)            Select Case keyascii        Case vbKeyEscape            txtBox.Text = strTextOnFocus        Case vbKey0 To vbKey9            'ok        Case vbKeyDelete            'ok        Case vbKeyBack            'ok        Case Asc(".")            'ok        Case 24 'Cut            'ok        Case 3  'Copy            'ok        Case 22 'Paste            'Only allow paste if the pasted values are numeric            If Clipboard.GetFormat(vbCFText) Then                If Not IsNumeric(Clipboard.GetText) Then                    Beep                    keyascii = 0                End If            End If        Case Else            Beep            keyascii = 0    End Select End Sub


This all works fine but what I would like to do is make it so when the user presses the enter key the validate event for that textbox is executed.

So my question is how do I manually raise the validate event for an arbitary textbox. ie, I don't know specifically which textbox i might be raising it for:


VB Code:
Private Sub RestrictTextNumeric(txtBox As TextBox, keyascii As Integer)            Select Case keyascii        Case vbEnter            *******************            Raise Validate event for txtBox Here            *******************        Case vbKeyEscape            txtBox.Text = strTextOnFocus        Case vbKey0 To vbKey9            'ok        Case vbKeyDelete            'ok        Case vbKeyBack            'ok        Case Asc(".")            'ok        Case 24 'Cut            'ok        Case 3  'Copy            'ok        Case 22 'Paste            'Only allow paste if the pasted values are numeric            If Clipboard.GetFormat(vbCFText) Then                If Not IsNumeric(Clipboard.GetText) Then                    Beep                    keyascii = 0                End If            End If        Case Else            Beep            keyascii = 0    End Select End Sub


An added problem is that a text box might not have a validate sub defined.

Thanks for any help.

Getting The Validate Event To Fire
I have a form with a number of controls on it with validate events associated with them. I also have a command button with the default property set to true.

My problem is that when I hit enter, the command button click event fires (as it should!) but the validate event on the control that has the focus does not fire.

The command button has its causesvalidation property set to true. How do I get the validate event to fire (without necessarily invoking the validate code from within the click event?

I have a feeling I have expressed this problem badly?!?

Triggering The Validate Event
Hello everybody,

I have the following problem.

When changing screens using menuoptions, or clicking any menuoption, the validateevent is not triggered.

Is there a way to trigger the validate events when clicking the menu? I already tried switching the focus to a different control (which has the causesvalidation property set to true). This trick works fine for forcing the LostFocus event when clicking the menu but not the Validate event.

I can think of dirty solutions, like calling the Validate sub when clicking the menu but if anyone knows a solution I hope he or she will be kind enough to tell me.

Thanks in advance.

Validate Event Procedure
I need to restrict the input to a combo box to integer only. I have read that the validate event procedure can do this, but the book did not include any exaples of how this would work.

Anybody know how this is done, either with the validate event procedure or through any other procedures?

Validate Event!! BIG PROBLEM
Hi everyone!

Could someone tell me what I am doing wrong!
I have created an ActiveX control which has a single constituent control (textbox) and I am using this control from within an HTML form. My control has several events, props and methods which all work fine except for the validate event which I am getting to fire but I CAN'T meke it keep the focus by setting the KEEPFOCUS (Cancel) property to true from within vbscript on the particular HTML page the control is within!

If you can help me than many thanks in advance!

Curious 'Validate' Event Behaviour
Hi folks.

Haven't been around for a bit, so I thought I would throw a good one at you for good measure.

I am writing a front-end to an application, which gathers an amount of input from the user, (via textboxes, checkboxes etc), and then attempts to store this in an Oracle database. To perform step-by-step input validation, I am using the 'Validate' event on the controls.

In the majority of cases, this works a treat, and provides excellent results. However some of the validations contain a small data retrieval, (where the input data is checked against a value in the database).

Now here is the odd part. If I key a value into a box that is validated against the database, and then click on a button somewhere else on the screen, (rather than tabbing to the next control), the following happens.

1. The 'Validate' event of the textbox fires.
2. The button becomes 'depressed' on the screen, but stays that way even with the mouse button released.
3. The 'Validate' event completes its work.
4. The 'Click' event of the button never fires, even if the 'Validate' event allows the focus to shift.

Once in this state, the button remains depressed, so long as the mouse is held over it. If you move the pointer out of the bounds of the button, the button returns to the 'raised' appearance', but sinks in again if you return the pointer to the bounds of the button control.

I know this problem can be cured by setting the 'CausesValidation' property of the button to False, but this defeats the object in my opinion. I need the textbox to validate before it permits the click of the button.

Any ideas?

Validate Event Not Firing On Unload
Good Morning,

I am attempting to use the data control validate event. It does not seem to fire on a form unload. Any thoughts?

Text Box Validate Event Won't Fire
I have several text boxes and a combo box on a form. The validate event won't fire for one of my text boxes. The causevalidation property is set to true for the all text and combo boxes. The strange thing about this bug is that if I set a break point in the text box where the validate event isn't firing my validation code works, but when I take the break point off and run without a break point it doesn't fire. Any help would be appreciated. Thanks!

Richard

Textbox Validate Event Skipped ?
I have some functions that keep users from entering invalid answers in text boxes that I call during the validate event of each control, but if you hit enter to trigger the default button it goes ahead and allows the users to move on to the next screen, even with invalid answers.

Does anyone know of a way to keep this from happening? Any help is appreciated!

Does Any Know About The Data Control Validate Event
Hiya

I can use a text box validation, but need to change this so that it uses the data control valdiate event instead. I think I need to change my texts boexes to look at the recordset but it then did not like the caancel = true. Tried to change from
visual basic
-----------------------------------------------------------------------

Private Sub txtField_Validate(Index As Integer, Cancel As Boolean)
If Val(txtField(2).Text) > 20 Then
MsgBox "Category must be between 1 and 20", vbOKOnly, "Category"
Cancel = True
End If
----------------------------------------------------------------------
TO
----------------------------------------------------------------------
Private Sub datStock_Validate(Action As Integer, Save As Integer)

If Val(datStock.Recordset.Category) > 20 Then
MsgBox "Category must be between 1 and 20", vbOKOnly, "Category"
datStock.Recordset.CancelUpdate
'txtField(2).Text = ""
End If

---------------------------------------------------------------------
I have tried to change this to the datacontrol validate event instead and where I have my text box array change to rdatstock.recordset.Category(or which evey field name I need) and to remove the cancel=true to datstock.recordset.cancelupdate, but I end up with a run time error of:

Runtime errorUpdate or cancelupdate without addnew or edit.

I tried changing this to:
--------------------------------------------------------------------
If Val(datStock.Recordset.Category) > 20 Then
MsgBox "Category must be between 1 and 20", vbOKOnly, "Category"
datStock.Recordset.CancelUpdate
'txtField(2).Text = ""
Else: datStock.Recordset.AddNew

End If
------------------------------------------------------------------------

The problem is, both will work but wjhen I go back over this the recordset comes up with the message box and then the 3020 error.

Has anyone come across this before?????

Any help gratefully accepted.....

Thanks

tracey

DtPicker Validate Event Not Works!
Why a dtpicker validate event object don't works inmediately when i change i.e. month value by keyboard and i make click in a toolbar button outside form? It aplyies the change after a little time. WHy?

Text Box Focus After Validate Event
Hello everybody

I do some validation check on a text box I have placed on a form. I would like the focus to remain on the same text box if the data are out of bound. How can I code that?

thx, in advance

George Papadopoulos

Validate Event With SetFocus Or ENTER Key
The validate event is not activated by either (a) using code (ie. SetFocus method) to set focus to another control or (b) pressing &lt;enter&gt; when there is a command button with its Default property set to TRUE.

I want to validate my textbox entry in both of these situations. Any suggestions?
Thanks.

Textbox Validate Event And Cancel
I use the Validate Event to Edit input in my Textboxes. I have a Cancel button setup on each form with Cancel=True set on it.

When a field that is Required Entry has focus and the User clicks the Cancel button, the Validate Event fires, due to the LostFocus that is taking place, and the Required Entry Edit fails. The ESC key does not cause the Validate Event to fire and thus ESC works just fine.

Can anyone give me an idea of something to check to keep my logic in the Validate Event from getting executed when the Cancel is clicked?????

Thanks,

John

How To Fire The Event Either Lostfocus Or Validate?
hi

i have design one application. in that i have two forms and i have located them parallely. one is left and one right side. in the right side form i have a combo box. i have written two events lostfocus and validate. and i have set style of the combo box to dropdown list. so now the uqestion is : when i change the item in the combo and clicked on the form then it works fine. and i have written the code in the two events. but after changing the item in the combo box and if i click directly on the left form the two events are not firing.... so what can i do fire the events...here after changing the item and clicking on the right side form , then it will fire , but after changing the item and click on the left side form directly then the events are not firing . so what is the so that i can handle the changes in the combo box.



thanks
---------------------------------------------
Srinivas.

TextBox Validate Event Problem
Hi,

I have a login screen, and have 2 textboxes to enter userid and password.
When program start, the focus should be in the txt_userid. If user enter invalid userid, he will get errro msg "Invalid Userid" . If correct, then focus move to txt_pwd. If user enter invalid pwd, he will get error msg, etc.

All above functions work well now except i find following problem.
I added a button on login screen named 'Cancel'. In click event, i just put one line code "Unload me". Problem here is if I click on this button before i entered a valid userid in txt_userid, i will get error msg "Invalid Userid". But why if i just click on cross on the righttop of the window to close the screen, i can close it without getting errror msg?

Rgds
Grace





Edited by - weihong321 on 11/27/2003 3:39:07 PM

Validate Event Not Triggered With SSTab
I placed 2 text boxes on one sheet of an SSTab control.
When the user switches tabs the Validate Event is not triggered.
Does any one have a solution?

Beforeupdate Event Procedure To Validate Form
hi all hope all is well

i am using microsoft access XP. i have a Mainform which has a subform in it. The sub form is linked with the Main form. The Mainform - ID - is the Master Field and the subform -SUPPLIERAUTHORITYNUMBER - is the Child field. That is what links the Mainform and the Subform together.

I am adding validation to the Mainform by using the the beforeupdate event of the Mainform. I dont know how I should code for the Mainform and Subform to be checked after Mainform and the SubForm fields have been filled with data from the user, so if the user left a field empty it will pop up a message box.

i have added code to the beforeupdate event of the Mainform which is as follows:


Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me![supplierid] = 0 Then
MsgBox "Supplier Name is Required"
supplierid.SetFocus
If Me![authoritynumber] = 0 Then
MsgBox "Authority Number are Required"
authoritynumber.SetFocus
End If
ElseIf Me![authoritynumber] = 0 Then
MsgBox "Supplier Authority Number is Required"
authoritynumber.SetFocus
End If

End Sub

i have also added code in the subform before update event which is as follows:


Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me![bookname] = "" Then
MsgBox "BookName is required"
bookname.SetFocus
ElseIf Me![bookscategoryid] = 0 Then
MsgBox "BookCategory is Required"
bookscategoryid.SetFocus
ElseIf Me![quantityofitem] = 0 Then
MsgBox "Quantity is Required"
quantityofitem.SetFocus
End If

End Sub

can someone tell me how i can check that the Mainform fields and the subForm fields have been inputted by using the beforeupdate event in order to add another record?

thanks in advance.. sonia

Close Form From Controls Validate Event ??
In the validate event for the person id field of my form, I am doing some validation whereby I am checking the database for the existence of another form for the ID'd person. If an existing form is found i want to send a message to the screen and stop the user from continuing raising the form by closing it.

However it seems that VB wont allow you to unload a form in the validate event of a control. What is the best way to achieve what I want to do ???

Hope someone can help

thanks

Make Sure Lostfocus/validate Event Triggers
In general when you have a textbox normally best to use the validate or lostfocus event to execute some code when the focus is lost on that textbox (so when editing the textbox is done execute the code)

This normally is fine when staying inside vb forms,
but when changing from the VB form to let say notepad or word external application, the focus stays on the VB form's textbox and no code is executed and i do want te code to be executes, so maybe i have to force a lostfocus event when de form is no more activated (i allso tried to use the form events deactive, lostfocus and no succes, they are not triggered)
Any idea's?

Tabbing From A Textbox And Validate Event Problem
I have a form with a text box that uses the validate event, and works
fine, but I also want to validate when user hit TAB, how can I triger the
validate event when TAB is pressed???

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