Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / May 2007

Tip: Looking for answers? Try searching our database.

Passing a control with null value to a function

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Peg - 09 May 2007 19:44 GMT
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
mdullni1 - 09 May 2007 20:22 GMT
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?

>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
[quoted text clipped - 45 lines]
>
>End Function
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.