And Statement (1 Viewer)

durdle

Registered User.
Local time
Today, 13:44
Joined
May 7, 2002
Messages
130
Good day,

I am tring to validate a combo box then a textbox but I get the error "You can't reference a property unless it has focus...". The code I use is

Me.cbowaiting.Setfocus
If Me.cbowaiting.Text = "OTHER" And Me.waitingothercomments.Text = "" Then

'MsgBox "You must enter other comments, when 'Other" is selected above....", vbCritical

'Exit Sub

'End If

But I can't give focus to too controls @ once.

Any thoughts?

durdle
________
toyota innova history
 
Last edited:

KenHigg

Registered User
Local time
Today, 09:44
Joined
Jun 9, 2004
Messages
13,327
If (Me.cbowaiting.Text = "OTHER") And (Me.waitingothercomments.Text = "") Then


??
 

Mile-O

Back once again...
Local time
Today, 13:44
Joined
Dec 10, 2002
Messages
11,316
Don't use .Text then.


.Text requires that the cursor be in the control

Code:
If Me.MyCombo = [i]value[/i] And Me.MyTextbox = [i]value[/i] Then
 

KenHigg

Registered User
Local time
Today, 09:44
Joined
Jun 9, 2004
Messages
13,327
Mile-O-Phile said:
Don't use .Text then.


.Text requires that the cursor be in the control

Code:
If Me.MyCombo = [i]value[/i] And Me.MyTextbox = [i]value[/i] Then


Really. Hum.. Also, I've alway did Me!MyCombo. Can you just dot everything now or do you have to bang (!) some stuff?
 

durdle

Registered User.
Local time
Today, 13:44
Joined
May 7, 2002
Messages
130
I used the code below and I don't get an error msg but it will not go inside the if:

If Me.cbowaiting = "OTHER" And Me.waitingothercomments = "" Then

MsgBox "You must enter other comments, when other is selected above....", vbCritical

Exit Sub

End If

And when I actually put OTHER in the combo and no value for the textbox waitingothercomments, I don't get inside the If. Note: I have my combo based on a table, which only have one field, the values inside the textbox. Maybe I should look @ adding an ID(autonumber) to the table.

durdle
________
vaporizer guide
 
Last edited:

Mile-O

Back once again...
Local time
Today, 13:44
Joined
Dec 10, 2002
Messages
11,316
KenHigg said:
Really. Hum.. Also, I've alway did Me!MyCombo. Can you just dot everything now or do you have to bang (!) some stuff?

On a form, always use . - it helps to bind early and is great for detecting errors, and - from a compilation perspective - is faster.

Me.MyTextbox

compiler knows exactly what textbox is being referred to

Me!MyTextbox

compiler has to search to determine if there is a textbox by that name
 

KenHigg

Registered User
Local time
Today, 09:44
Joined
Jun 9, 2004
Messages
13,327
Check Me.waitingothercomments to see if it's null instead of ""

If Me.cbowaiting = "OTHER" And isnull(Me.waitingothercomments) Then

??
 

Mile-O

Back once again...
Local time
Today, 13:44
Joined
Dec 10, 2002
Messages
11,316
Code:
If Me.cbowaiting = "OTHER" And IsNull(Me.waitingothercomments) Then
Your textbox is not a NullString; it's a Null
 

durdle

Registered User.
Local time
Today, 13:44
Joined
May 7, 2002
Messages
130
That was it Ken and Mile.

What is the difference between "" and IsNull?
Do this apply to all textboxes?

durdle
________
tacuma
 
Last edited:

KenHigg

Registered User
Local time
Today, 09:44
Joined
Jun 9, 2004
Messages
13,327
I check for null everywhere; textboxes, query params, etc.

Good thread...
 

Mile-O

Back once again...
Local time
Today, 13:44
Joined
Dec 10, 2002
Messages
11,316
durdle said:
What is the difference between "" and IsNull?

"" - or to use its proper constant - vbNullString is a string with no characters
IsNull() is a function that determines whether an object contains a value or not.

I'm sure you when the differnce between vbNullString and Null.
So, again, vbNullString is a string with no characters (it's still a value though)
And Null is simply an empty value - it contains nothing.

Do this apply to all textboxes?

Yes.

You can use Me.MyTextBox.Text = vbNullString as, in this occasion, you are looking at the string value of the textbox. However, as you have seen, you need to set the focus to it - a waste of time, in my opinion.
 

Users who are viewing this thread

Top Bottom