Results 1 to 7 of 7
  1. #1
    jabourgeois1 is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2017
    Posts
    17

    MS access has generated the following error "94 Invalid use of Null"

    This is the complete section of code that I am working on. I tried and failed with the dlookup and recordset at least with the if statement it is doing half of what I am trying to accomplish.

    Dim lworkout As TempVars
    Dim lmin As Integer
    TempVars!lworkout = Me.frmClockIn_SUB!TimeOUT.Value

    Me.txtLastworkout = TempVars!lworkout
    lmin = DateDiff("n", Me.txtLastworkout, Now)


    If lmin <= 240 Then


    MsgBox "You must have a minimum 4 hours between Workouts!!"
    DoCmd.OpenForm "frmHoursOfOperation"
    DoCmd.Close acForm, "frmClockin"
    Exit Sub


    End If

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    Why are you using a tempvar? Just use a regular variable,
    dim lWorkout

    lWorkout= Dlookup....

  3. #3
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Based on what was posted, don't need the integer variable either
    Code:
    If DateDiff("n", Me.txtLastworkout, Now) < 240 Then 
      msgbox "You must have a minimum 4 hours between Workouts!!"
      DoCmd.OpenForm "frmHoursOfOperation"
      DoCmd.Close acForm, "frmClockin"
      Exit Sub
    End If
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    have you tried stepping through the code to see what value is null? or at what point the error is generated? Do you have Option Explicit at the top of your module? Does the code compile?

    In vba Now is a function so usually has opening and closing brackets - Now(). It may be the 2016 compiler is being more pedantic about using correct syntax.

  5. #5
    jabourgeois1 is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2017
    Posts
    17

    Smile Workout tracking Database

    To answer the questions

    ranman256- After trying two other methods an not being successful that is what pop into my head to try and at least I was getting some sort of return when I hover the text.

    Micron-I went with your solution which seems to be the easiest. I did have to change the Me.txtLastworkout to Me.frmclockin_sub!TimeOUT. I was going to go with either a hidden/visible text box to pull from the sub form and do the calculation off of it. Which is where I was getting stuck. When the student clockin and it was the very first time or if they hit the clock in button when they where suppose to clockout it would throw out the invalid use of null statement.

    Ajax-Yes, I just could not get it to handle if the text box end up with a null value. This happened When the student clockin and it was the very first time or if they hit the clock in button when they where suppose to clockout it would throw out the invalid use of null statement.

    Thank you to all three of you. I am sure I will be back. As I finished with the first part of this database and am getting ready to tackle part 2 & 3.

    P.S. I have attached the full database. It is working the part that I will be working on next will be from the main page the patron and employee buttons and everything it deal with. I am sure there are some better ways to do what I did but I am always willing to make improvements. No reason to reinvent the wheel so if some one wants to utilize what I have started go for it. I will try to post My updates and as I get more of it completed.
    Attached Files Attached Files

  6. #6
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Had a quick look at your db. Don't agree with the design. There ought to be a students table containing all attributes (as fields) of a student, with a form to facilitate the adding of new ones. You have a table for student addresses, which is not required and only adds overhead. Address info is one/some of those attributes. Information related to student activities would be in those activity tables, or 1 activity table if that makes more sense. Then, the student id is a fk in those tables - you don't put a fk field in a main table and call it such, then use that same field name everywhere else. StudentID would be a fk in any activity or otherwise related table, and it would be fine to identify it as such in those tables, but not in the parent (main) table. With your design, I wasn't able to easily figure out how to add a new student. Also, your buttons indicate there will be other 'types' besides students, but maybe you haven't gotten that far yet. If not, time to step back and think about your design before going too far.

    Looking a bit further, I see you hid most of the forms. Makes it more difficult if you're looking for help. Not sure - you didn't ask, but then why post the db if not? Maybe you weren't expecting design critique. So when I look at student address form, not only does it load with the first table record, there is no clue as to whose address you'd be editing, and there's no way to add a new record. How were you planning to populate the tables - directly? Not advisable. Anyway, I should stop there. While the intent is constructive advice, I may be coming across as criticizing.

  7. #7
    jabourgeois1 is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2017
    Posts
    17
    Micron-- I have no delusions on how Good/Bad this is, so if you want to criticize please feel free. I am a big boy and I don't hold grudges. This was my first attempt at building a database and writing code since I took a VB class 10+ years ago. That was when windows still had VB loaded as a program, and its had been 20+ years since I did anything with microsoft ACCESS. I was voluntold to do this and it is not the first choice but as I have had some exposure to it compared to python or django, I gave it a shot. I set it up the way the person who requested wanted as far as the input. All I know is that it is working for what they need and he seems to be happy with it. so for me that is good, not to say I wont continue to try to improve it because as I figure more out it will change as well. Thanks for the input.

    Sorry I forgot to unhide all the other forms and stuff. I set it up that way so when they need a fresh install, they would make a copy of the database, delete the visible items, then copy the original and paste without data.

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

Similar Threads

  1. Replies: 3
    Last Post: 11-13-2013, 08:56 AM
  2. Replies: 5
    Last Post: 06-26-2013, 02:29 PM
  3. Replies: 4
    Last Post: 06-24-2013, 07:12 AM
  4. StrComp causing "Invalid use of Null" error
    By sephiroth2906 in forum Programming
    Replies: 5
    Last Post: 09-15-2011, 07:06 PM
  5. Update query from form "invalid use of null"
    By Lady_Jane in forum Programming
    Replies: 4
    Last Post: 08-16-2011, 01:37 PM

Tags for this Thread

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