Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2003
    Location
    Arizona
    Posts
    9

    Question Unanswered: Can someone verify this code?

    I am not a programmer so I don't know how to code whatsoever.

    Vestigo gave me this code to create a unique job number. I put this code into a button to generate a Work Request number but when I click on the button I get a "Runtime Error '94' Invalid use of Null".

    Here is the code:

    Private Sub Work_Request_Click()
    '**********************************
    ' Code made by Vestigo, 051203
    '**********************************
    ' Add this code to a button on your form.
    ' Create the table 't-Work' with one autonumber field (called Auto, not important)
    ' and one text field (length 8) called 'Work_Request_Number'
    '
    ' Put in some figures to 'Work_Request_Number' in your table, like:
    ' 04120301
    ' 05120301
    ' 05120302
    ' Manipulate the 'Work_Request_Number' in order to test the code

    Dim Today As String, Last As String, Next_Request As String, Next_Count As Integer
    Today = Format(Now(), "ddmmyy")
    RIGHT HERE Last = Left(DLast("Work_Request_Number", "t-Work"), 6)

    If Today = Last Then
    Next_Count = Int(Right(DLast("Work_Request_Number", "t-Work"), 2)) + 1
    Next_Request = Format(Now(), "ddmmyy") & Right("0" & Next_Count, 2)
    Else
    Next_Request = Format(Now(), "ddmmyy") & "01"
    End If

    MsgBox "Next_Request (to be inserted to your table): " & Next_Request


    End Sub

    Where I typed RIGHT HERE is where the Debug function highlights. If anyone can help fix this that would be great.

  2. #2
    Join Date
    Nov 2003
    Posts
    1,487
    Your code works fine....perhaps check your spelling. Make sure you have Option Explicit at the top of your code module. It may point the problem out to you.

  3. #3
    Join Date
    Dec 2003
    Location
    Arizona
    Posts
    9

    Can you help Cyberlynx?

    Here is what I have. The table and form are t-Work. I want the Work Request number to be placed in the text box when generated.
    Attached Files Attached Files

  4. #4
    Join Date
    Nov 2003
    Posts
    1,487
    Checking it out...Get back to you in a minute or so.

  5. #5
    Join Date
    Nov 2003
    Posts
    1,487
    Ok...Everything is working fine (at least for me). I left Rem statements explaining everything I've done within the code for your generate button.

    Always remember...you need a least one record in your table to give DLast the opportunity to provide the string data needed for the Left$ function. The Left$ (or Left) function can not work with Null.
    Attached Files Attached Files

  6. #6
    Join Date
    Dec 2003
    Location
    Arizona
    Posts
    9

    Thanks for the help

    CyberLynx,

    I appreciate the help.. This has been driving me nuts...

  7. #7
    Join Date
    Nov 2003
    Posts
    1,487
    Glad to have been of some assistance to you. Keep up the good work.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •