How do you bypass the Null value in VB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anoble1
    New Member
    • Jul 2008
    • 246

    How do you bypass the Null value in VB

    I have a form that has multiple fields. It has 4 fields. One of them happens to be a comment field. Sometimes there is a comment and sometimes there is not. When there is not a comment I get an error. When I debug it stops here where I have it underlined: .body = Me.Comments

    How do I make it save not matter whats in the box?

    Code:
    Private Sub cmdAddToCalendar_Click()
        On Error GoTo Add_Err
    
        'Save record first to be sure required fields are filled.
        DoCmd.RunCommand acCmdSaveRecord
    
        Dim objOutlook As Outlook.Application
        Dim objAppt As Outlook.AppointmentItem
        Dim objRecurPattern As Outlook.RecurrencePattern
    
        Set objOutlook = CreateObject("Outlook.Application")
        Set objAppt = objOutlook.CreateItem(olAppointmentItem)
    
        With objAppt
            .Start = DateAdd("d", 90, LastEmploymentDate.Value) '& " " & Me!ApptTime
            .Duration = 1440
            .Subject = "Notify " & Me.NotifyName & " about " & Me.EmployeeName
            .ReminderMinutesBeforeStart = 15
            .ReminderSet = True
            [U].Body = Me.Comments[/U]
            .Save
            .Close (olSave)
        End With
        'Release the AppointmentItem object variable.
        Set objAppt = Nothing
    
        'Release the Outlook object variable.
        Set objOutlook = Nothing
    
        MsgBox "Appointment Added!"
    
        Exit Sub
    
    Add_Err:
        MsgBox "Error " & Err.Number & vbCrLf & Err.Description
        Exit Sub
    End Sub
  • Delerna
    Recognized Expert Top Contributor
    • Jan 2008
    • 1134

    #2
    Try this
    additions and changes are bolded
    Code:
    Private Sub cmdAddToCalendar_Click() 
        On Error GoTo Add_Err 
      
        'Save record first to be sure required fields are filled. 
        DoCmd.RunCommand acCmdSaveRecord 
        [B]Dim strBdy as string[/B]
        Dim objOutlook As Outlook.Application 
        Dim objAppt As Outlook.AppointmentItem 
        Dim objRecurPattern As Outlook.RecurrencePattern 
      
        Set objOutlook = CreateObject("Outlook.Application") 
        Set objAppt = objOutlook.CreateItem(olAppointmentItem) 
    [B]    strBdy=Me.Comments [/B]
        [B]If isnull(strBdy) then strBdy ="" [/B]
        With objAppt 
            .Start = DateAdd("d", 90, LastEmploymentDate.Value) '& " " & Me!ApptTime 
            .Duration = 1440 
            .Subject = "Notify " & Me.NotifyName & " about " & Me.EmployeeName 
            .ReminderMinutesBeforeStart = 15 
            .ReminderSet = True 
            .Body = [B]strBdy[/B]
            .Save 
            .Close (olSave) 
        End With 
        'Release the AppointmentItem object variable. 
        Set objAppt = Nothing 
      
        'Release the Outlook object variable. 
        Set objOutlook = Nothing 
      
        MsgBox "Appointment Added!" 
      
        Exit Sub 
      
    Add_Err: 
        MsgBox "Error " & Err.Number & vbCrLf & Err.Description 
        Exit Sub 
    End Sub

    EDIT
    oops, did a typo
    Dim strBody
    ....
    and then used it as Bdy instead of strBdy

    Thanks OldBirdman

    Comment

    • Delerna
      Recognized Expert Top Contributor
      • Jan 2008
      • 1134

      #3
      That's a quick and dirty fix.
      There are other things you can do to ensure that null is eliminated as a problem in the first place. Like setting default values for the fields in your table

      Comment

      • anoble1
        New Member
        • Jul 2008
        • 246

        #4
        That worked GREAT! Thanks!

        Comment

        Working...