Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

control validation problems in XL 97 VBA

Status
Not open for further replies.

taupirho

Programmer
Jun 25, 2002
680
GB
I have a date picker field, a text field and an exit button on my userform.
I have coded some validation in the exit event of the text field which works as expected except when I click on the drop down arrow of my date picker control. Although I get my validation message OK it still insists on causing the calendar part of the date picker control to appear even though I have a cancel=true and textbox1.setfocus statements in my textbox validation routine. My other problem is that the textbox validation also fires when I click on my exit button even though I have its getfocusonclick property to false. Any help on these two problems is much appreciated.
 
Post your code (just the essential parts). I'm sure we can help with both issues.
Rob
[flowerface]
 
Here is my validation code as requested:-

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)

Cancel = False
If TextBox1.Value = "" Then
Exit Sub
Else
Dim SQLstr As String


Set DBnum = New Connection
DBnum.CursorLocation = adUseClient
DBnum.Open "PROVIDER=MSDASQL;dsn=Text Files;uid=;pwd=;database=;"

Set ADOnum = New Recordset
SQLstr = "select num from c:\valid_nums.csv where num=" & UserForm2.TextBox1.Value

ADOnum.Open SQLstr, DBnum, adOpenStatic, adLockOptimistic

If ADOnum.RecordCount < 1 Then
MsgBox (&quot;Invalid number, please re-enter&quot;)
Cancel = True
UserForm2.TextBox1.SetFocus
End If

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top