Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper way to check if an unbound control has a value

Tags:

vba

ms-access

Simple scenario: a form and one text box (unbound), Text1.

If "" <> Text1 Then
    MsgBox "Not Empty"
End If

The above code works. The expression ""<> Text1 evaluates to True if the text box contain characters.

The opposite doesn't work, regardless of the text box is empty or not:

If "" = Text1 Then  ' or alternatively, False = ("" <> Text1)
     MsgBox "Empty!"
End If

Can you clarify this issue?

like image 799
Nick Dandoulakis Avatar asked Sep 08 '09 09:09

Nick Dandoulakis


People also ask

What is an unbound control in access?

Unbound control A control that doesn't have a source of data (such as a field or expression) is called an unbound control. You use unbound controls to display information, pictures, lines or rectangles. For example, a label that displays the title of a form is an unbound control.

What is bound and unbound?

Bound control – associated with a field in an underlying table. Use bound controls to display, enter, and update values from fields in the database. Unbound control – does not have a data source. Use unbound controls to display pictures and static text.

What is bound control in access?

Bound controls are bound or connected to an underlying field in a table or query. You use bound controls to display, enter, and update field values in your database. The fields that you can add to a form using the Field List are all examples of bound controls.

What is bound form and unbound form?

So, a bound form has a RecordSource, a table or query to which the form is "tied" or "based". An unbound form does not have a RecordSource, that doesn't mean it can't contain data, but the programmer will have to bring that data in manually, where a bound form automatically is associated with some data.


1 Answers

The textbox is usually null if it does not contain anything, this is not the same as a zero length string (""). It can often be best to use:

If Trim(Text1 & "") = vbNullString
   'Empty

This will be true if the textbox contains spaces, a zero length string or null.

like image 157
Fionnuala Avatar answered Sep 27 '22 18:09

Fionnuala