Results 1 to 4 of 4
  1. #1
    Thumbs is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2012
    Posts
    25

    Help with Null value handling

    Hello folks, have a fairly simple question that I am sure has a simple solution, I am just not experienced enough to know the answer.

    I have the following VBA code on an "On Enter" event on a field. The code work beautifully for what I want it to do, unless the user clicks in an empty field to create a new record, at which point access returns an error saying "Invalid use of Null". I know I need to include Null handing for this, but I dont know where in the code I need to add it or specifically how I would do so for this specific instance.



    Code:
    Private Sub OlSerialNumber_Enter()
    Dim dbs As Database, strSQL As String
    Dim PassID As String
    PassID = Me!OlDescription
    Set dbs = CurrentDb
    strSQL = "SELECT [AssetData].[SerialNumber], [AssetData].[Identifier] FROM AssetData Left JOIN OperatingLog ON [AssetData].[Identifier] = [OperatingLog].[OlDescription] WHERE [AssetData].[Identifier]='" & PassID & "';"
    Me!OlSerialNumber.RowSource = strSQL
    End Sub
    Any help would be much appreciated, as I am going to need to replicate this code to several other fields on the form for the auto update process I have defined.

    EDIT: I dont know why i didnt debug the code before posting this, but the debug flashes the line where I declare the value for the varibale "PassID".

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Before the line setting the variable test to mak sure it contains a value:

    If Len(Me.SomeControl & vbNullString) = 0 Then

    And only run the rest of the code if it does.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Thumbs is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2012
    Posts
    25
    Thanks for the suggestion Paul, but that didnt seem to solve the issue; However, I was able to solve the issue by using

    If Not IsNull(FieldName) Then...

    Your post jogged my memory for that line of code. Thanks!

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    They should both work (yours reverses the logic). Mine has the advantage of testing for a zero length string as well as Null.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 02-23-2012, 02:27 PM
  2. Finding the Max Date and Null Values if Null
    By SpdRacerX in forum Queries
    Replies: 1
    Last Post: 02-03-2012, 06:29 AM
  3. Error Handling
    By jgelpi16 in forum Programming
    Replies: 4
    Last Post: 09-14-2010, 12:17 PM
  4. Error Handling
    By trb5016 in forum Access
    Replies: 2
    Last Post: 08-10-2010, 08:37 AM
  5. #error handling
    By mws5872 in forum Access
    Replies: 4
    Last Post: 05-12-2010, 07:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums