Results 1 to 7 of 7
  1. #1
    cec is offline Advanced Beginner
    Windows 2K Access 2003
    Join Date
    Apr 2012
    Posts
    42

    Getting #Error Message

    I have a code that gives me the "#Error" message if the text box that it is referencing is blank.... how can I avoid this from displaying on the form view? as some of the text boxes will be blank...



    thanks

  2. #2
    R_Badger is offline Knows a few tricks
    Windows XP Access 2003
    Join Date
    Feb 2012
    Location
    Suffolk, UK
    Posts
    262
    Can you give more detail, its a little vague?
    What is the code?

    Having just said that however you may find the nz function useful, reference:
    http://msdn.microsoft.com/en-us/libr...ice.11%29.aspx

    Just in case this helps any more;
    nz([forms]![form_name]![text_box_name],value_if_textbox_is_null)

  3. #3
    cec is offline Advanced Beginner
    Windows 2K Access 2003
    Join Date
    Apr 2012
    Posts
    42
    Hi R Badger

    this is the code

    Public Function WorkingHrsMins(StartDate As Date, EndDate As Date) As String
    '................................................. ...................
    ' Name: WorkingHrsMins
    ' Inputs: StartDate As Date & time
    ' EndDate As Date & time
    ' Returns: String- number of hours & minutes not inclusive of weekends
    ' Author: Arvin Meyer
    ' Date: February 19, 1997
    ' Modified by Steve S (ssanfu)
    ' Date: April 11, 2012
    ' Comment: Accepts two dates and returns the number
    ' of work hours and minutes between 8am and 8pm
    ' Note that this function does not account for holidays.
    '................................................. ...................
    On Error GoTo Err_WorkingHrs

    Dim intCountDays As Integer
    Dim intHours As Integer
    Dim intMinutes As Integer
    Dim intTotalMin As Integer
    Dim dtStart As Date
    Dim dtEnd As Date
    Dim dtTemp As Date
    Dim tmStart As Date
    Dim tmEnd As Date

    intMinutes = 0
    intHours = 0
    intCountDays = 0
    intTotalMin = 0

    'check end date > start date
    If EndDate < StartDate Then
    dtTemp = StartDate
    StartDate = EndDate
    EndDate = dtTemp
    End If

    'get just the date portion
    dtStart = Int(StartDate)
    dtEnd = Int(EndDate)
    'get just the time portion
    tmStart = StartDate - dtStart
    tmEnd = EndDate - dtEnd

    If dtStart <> dtEnd Then

    'skip the first day
    dtStart = dtStart + 1

    Do While dtStart < dtEnd
    'Make the above < and not <= to not count the EndDate

    Select Case Weekday(dtStart)
    Case Is = 1, 7
    'do nothing
    Case Is = 2, 3, 4, 5, 6
    intCountDays = intCountDays + 1
    End Select
    dtStart = dtStart + 1
    Loop
    intTotalMin = intCountDays * 720

    'first day minutes
    intTotalMin = intTotalMin + DateDiff("n", tmStart, #8:00:00 PM#)
    'Last day minutes
    intTotalMin = intTotalMin + DateDiff("n", #8:00:00 AM#, tmEnd)
    Else
    intTotalMin = DateDiff("n", StartDate, EndDate)
    End If

    intHours = intTotalMin \ 60 'hours
    intMinutes = intTotalMin Mod 60 'minutes

    'return value
    WorkingHrsMins = intHours & "hrs " & intMinutes & "min"

    Exit_WorkingHrs:
    Exit Function

    Err_WorkingHrs:
    Select Case Err

    Case Else
    MsgBox Err.Description
    Resume Exit_WorkingHrs
    End Select

    End Function

  4. #4
    RagJose is offline Seasoned user
    Windows XP Access 2002
    Join Date
    Apr 2012
    Location
    Brazil
    Posts
    42
    I would not declare the function arguments as Date if there is a chance a Null value can come through. I'd declare the arguments Variant and test them with IsNull() before using them (or not) in calculations. Suggest you try that.

  5. #5
    cec is offline Advanced Beginner
    Windows 2K Access 2003
    Join Date
    Apr 2012
    Posts
    42
    Not sure that I follow that i'm a new at this...

  6. #6
    RagJose is offline Seasoned user
    Windows XP Access 2002
    Join Date
    Apr 2012
    Location
    Brazil
    Posts
    42
    Okay, your function returns a string like "hh hrs mm min". Let's say if you have blank arguments you would want "No hrs worked" as result. I edited your code to do that. Changes are in bold. Replace the result string as you see fit. Hope this works as you expect.

    Public Function WorkingHrsMins(StartDate As Variant, EndDate As Variant) As String
    '................................................. ...................
    ' Name: WorkingHrsMins
    ' Inputs: StartDate As Date & time
    ' EndDate As Date & time
    ' Returns: String- number of hours & minutes not inclusive of weekends
    ' Author: Arvin Meyer
    ' Date: February 19, 1997
    ' Modified by Steve S (ssanfu)
    ' Date: April 11, 2012
    ' Comment: Accepts two dates and returns the number
    ' of work hours and minutes between 8am and 8pm
    ' Note that this function does not account for holidays.
    '................................................. ...................
    On Error GoTo Err_WorkingHrs

    Dim intCountDays As Integer
    Dim intHours As Integer
    Dim intMinutes As Integer
    Dim intTotalMin As Integer
    Dim dtStart As Date
    Dim dtEnd As Date
    Dim dtTemp As Date
    Dim tmStart As Date
    Dim tmEnd As Date

    If IsNull(StartDate) or IsNull(EndDate) Then
    WorkingHrsMins = "No hrs worked"
    Exit Function
    End If


    intMinutes = 0
    intHours = 0
    intCountDays = 0
    intTotalMin = 0

    'check end date > start date
    If EndDate < StartDate Then
    dtTemp = StartDate
    StartDate = EndDate
    EndDate = dtTemp
    End If

    'get just the date portion
    dtStart = Int(StartDate)
    dtEnd = Int(EndDate)
    'get just the time portion
    tmStart = StartDate - dtStart
    tmEnd = EndDate - dtEnd

    If dtStart <> dtEnd Then

    'skip the first day
    dtStart = dtStart + 1

    Do While dtStart < dtEnd
    'Make the above < and not <= to not count the EndDate

    Select Case Weekday(dtStart)
    Case Is = 1, 7
    'do nothing
    Case Is = 2, 3, 4, 5, 6
    intCountDays = intCountDays + 1
    End Select
    dtStart = dtStart + 1
    Loop
    intTotalMin = intCountDays * 720

    'first day minutes
    intTotalMin = intTotalMin + DateDiff("n", tmStart, #8:00:00 PM#)
    'Last day minutes
    intTotalMin = intTotalMin + DateDiff("n", #8:00:00 AM#, tmEnd)
    Else
    intTotalMin = DateDiff("n", StartDate, EndDate)
    End If

    intHours = intTotalMin \ 60 'hours
    intMinutes = intTotalMin Mod 60 'minutes

    'return value
    WorkingHrsMins = intHours & "hrs " & intMinutes & "min"

    Exit_WorkingHrs:
    Exit Function

    Err_WorkingHrs:
    Select Case Err

    Case Else
    MsgBox Err.Description
    Resume Exit_WorkingHrs
    End Select

    End Function

  7. #7
    cec is offline Advanced Beginner
    Windows 2K Access 2003
    Join Date
    Apr 2012
    Posts
    42
    Thanks worked like a charm!

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

Similar Threads

  1. On Error Message
    By rlsublime in forum Programming
    Replies: 5
    Last Post: 03-14-2012, 02:53 PM
  2. Error Message???????????
    By bopsgtir in forum Access
    Replies: 1
    Last Post: 10-02-2011, 06:10 PM
  3. Error Message
    By Juan4412 in forum Forms
    Replies: 5
    Last Post: 03-06-2011, 04:22 PM
  4. error message
    By ngeng4 in forum Forms
    Replies: 85
    Last Post: 03-25-2010, 06:47 AM
  5. If / Then Error Message
    By Schwagr in forum Forms
    Replies: 4
    Last Post: 03-30-2006, 06:28 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