Passing a control with null value to a function

  • Thread starter Peg via AccessMonster.com
  • Start date
P

Peg via AccessMonster.com

I have read the posts on passing a control to a function. As long as my
control has some data in it, the function works fine. If my control is null
I get a message "You tried to assign a null value to a variable that is not a
variant data type".

I have tried to set the value of the text control to "" before passing it,
but I still get the error. Any suggestions?

Here is the code:

Private Sub txtAddr1_BeforeUpdate(Cancel As Integer)
If Nz(Me.txtAddr1, "") = "" Then
Me.txtAddr1 = ""
End If
Cancel = Check_Length(Me.txtAddr1, mlngAddr1_Lngth, True)

End Sub

Function Check_Length(txtCtrl As TextBox, lngLngth As Long, _
bln0Lngth_allowed As Boolean) As Boolean
'*****************************************************************************
'* Function: Check_Length
*
'* Purpose: Displays a message if the field length is too long or 0.
*
'* Returns true if error found.
*
'*****************************************************************************
Check_Length = False
If Len(Nz(txtCtrl.Text, "")) > lngLngth Then
MsgBox "Only " & lngLngth & " characters are allowed." & vbCrLf _
& "Remove " & (Len(txtCtrl.Text) - lngLngth) & " characters." _
, vbExclamation + vbApplicationModal _
, "Too Many Characters"

Check_Length = True
txtCtrl.BackColor = vbRed
ElseIf Len(Nz(txtCtrl.Text, "")) = 0 And bln0Lngth_allowed = False Then
MsgBox "Field cannot be blank." & vbCrLf _
, vbExclamation + vbApplicationModal _
, "Blank Field Invalid"

Check_Length = True
txtCtrl.BackColor = vbRed
Else
txtCtrl.BackColor = vbWhite
End If

End Function
 
M

mdullni1 via AccessMonster.com

I wanted to delete this post because I figured out that the recordsource view
is somehow limiting NULL values. The underlying table allows NULL, so I am
not sure why this is happening. The view is a one-to-one, but I am only
updating one table. Any ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top