Results 1 to 8 of 8
  1. #1
    TerraEarth is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    86

    Run-time error 94, invalid use of null

    I'm having a strange problem with one of my form buttons. Essentially the button is a save button that saves the record after validating that the record is accurate and complete.



    This line is what is giving me the issue:

    Code:
    If CStr(Me!Child86.Form!FYSummary.Value) <> "" Then ' Triggers Error 94
    'Do stuff
    End If
    Child86 is the name of a subform on my form.
    FYSummary is the name of a field (integer) on the subform that I want to check (it shouldn't be empty!)
    However, even when the field on the subform is filled out, Me!Child86.Form!FYSummary.Value returns Null which triggers the run-time error 94.
    How can this be? How can FYSummary be a null value when it is filled out with numbers? For example:

    FYSummary:
    12
    13
    14
    15

    This line of code was working just fine a few days ago, I am not sure why Access is acting up now when nothing has been changed to the FYSummary field itself. Any ideas?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Conversion functions error on Null. Are you sure every record has data? If yes, that is odd.

    Use Nz() or IsNull() functions instead. Or:

    If Me.Child86!FYSummary & "" = "" Then

    Suggest naming control different from field:

    If Me.Child86.Form.tbxFYSummary & "" = "" Then

    Notice the shorter referencing and use of dot.

    Suggest you give subform container more meaningful name.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    OR
    If isNull(Me!Child86.Form!FYSummary.Value) then

  4. #4
    TerraEarth is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    86
    Right, however, Me!Child86.Form!FYSummary.Value returns NULL even before it is passed to the conversion function.

    In other words, despite the field having several inputted values in the subform, it is still seen as being empty by VBA, any idea what is causing this?


    Code:
    If CStr(Me!Child86.Form!FYSummary.Value) <> "" Then
            If (Me!Child86.Form!FYSummary.Value < -1) Or (Me!Child86.Form!FYSummary.Value > 100) Then
                MsgBox "Please make sure to enter a year between 1 and 99 (corresponding to any year between 2001 and 2099)"
                Exit Sub
            End If
    'SQL queries to update my tables with form entry
    End If

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Are you validating data just entered before it is committed to table? What event is this code in?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    TerraEarth is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    86
    Are you validating data just entered before it is committed to table?
    The form/subform is based off two tables, tTempDataEntry (form) and tTempFiscalYears (subform)
    They are connected/linked by a ID key.
    The validation does not check the tables (tTempDataEntry/tTempFiscalYears), rather it checks the values in the forms itself.
    i.e.
    Code:
    Me!Child86.Form!FYSummary.Value (for the subform) 'Check if this value is empty or null, if so then don't save
    Me!POCName (for the main form) 'Check if this value is empty or null, if so then don't save
    Me!POCEmail (for the main form) 'Check if this value is empty or null, if so then don't save
    Me![InsertMainFormFieldNameHere] 'Check if this value is empty or null, if so then don't save

    etc...

    What event is this code in?
    This code is contained in the on-click event of my 'Save' button. It first checks that every entry in the form has an input, and if these inputs are in the correct format. It then runs a series of SQL queries to update my database tables with the form tables and then it wipes the form tables clean.

    So this error occurs very early in my code, in the initial checking phase. The snippet is in the format shown above in the previous posts. A few days ago if my subform had the following entries:

    FYSummary:
    12
    13
    14
    15

    Me!Child86.Form!FYSummary.Value would return an integer 12 and my check ran fine just then.

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Think I edited my comments in post 2 after you read it. Review again.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    TerraEarth is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    86
    Thanks for the suggestions, I'll try to tidy up my code with those implementations.

    I was able to figure out why my code was having the error. I had hidden the columns of the table so for some reason those columns were not updating as normal. My table looks like this:


    Auto | ContractID | FYSummary | Calc
    1 | abcd | 17 | abcd17

    Auto is a autokey and also the primary key
    ContractID is the foreign key that links to the main form
    FYSummary represents a year (17=2017)
    Calc is a unique index calculated field. It automatically concatenates contractID and FYSummary I hid the columns using this code:

    Code:
    Private Sub Form_Load()
        Forms!fRecordEntry!Child86.Form!Auto.ColumnHidden = -1
        Forms!fRecordEntry!Child86.Form!Calc.ColumnHidden = -1
        Forms!fRecordEntry!Child86.Form!ContractID.ColumnHidden = -1
        CurrentDb.Execute "DELETE * FROM tTempDataEntry;", dbFailOnError 'tTempDataEntry is table sourcing the main form
        CurrentDb.Execute "DELETE * FROM tTempFiscalYears;", dbFailOnError ' tTempFiscalYears is the table sourcing the subform
        Me.Requery
    End Sub
    When I changed the ColumnHidden property back to false ( = 0) my code worked and when I queried the value of FYSummary field in my form it returned the year (17). Is there a reason why hiding the column makes their values null?

    When I enter in a ContractID in the mainform this automatically sets the ContractID of the subform, then all I really need to do is enter in a year for the entry to be considered complete. As soon as a contractID is entered a autokey should be generated into AUTO and the calc field is set to automatically concatenate the ContractID and Year. However, when I queried all four of these fields, the only non-null value returned was from ContractID; Auto, FYSummary and Calc were all null.

    EDIT:

    Turns out, if you have columns hidden, they don't update properly, but using a me.requery fills out all the fields properly as it ought to be. How bizarre.

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

Similar Threads

  1. Replies: 3
    Last Post: 05-10-2018, 07:48 AM
  2. Invalid use of NULL error
    By CHEECO in forum Access
    Replies: 13
    Last Post: 03-16-2016, 07:20 PM
  3. Run time error '94': Invalid Use of Null... help
    By batowl in forum Programming
    Replies: 3
    Last Post: 05-14-2014, 01:58 PM
  4. Replies: 1
    Last Post: 03-22-2013, 09:59 AM
  5. Error 94: Invalid Use of Null
    By athomas8251 in forum Forms
    Replies: 3
    Last Post: 11-09-2011, 11:46 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