Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    5 Star Lounger bfxtrfcmgr's Avatar
    Join Date
    Aug 2002
    Location
    Fresno, California, USA
    Posts
    995
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Invalid use of Null (Msg) (2002 SP-2)

    In the following code the only real variable is strRecipient = Me.CarrierName. If the operator fails to select the CarrierName on the form, but clicks the cmdbtn to invoke this code, he gets the MSmsg "Invalid use of Null" warning. The problem is that there is no description of where the null entry is located, and this form has nearly fifty entries. I would like to create my own pop-up to alert to the error and to describe where the null entry is located (i.e. "You must first select a carrier"). I suspect it would go in the ErrHandler, but I'm not confident of that.

    Private Sub cmdLoadConfirmEmail_Click()
    On Error GoTo ErrHandler
    'Email confirm to assigned carrier

    Dim strReportName As String
    Dim strRecipient As String
    Dim strSubject As String
    Dim strMessage As String
    Dim blnEditMail As Boolean

    strReportName = "rptLoadConfirmSingleEmail"
    strRecipient = Me.CarrierName
    strSubject = "Load Confirm Attached for PRO# " & Me.ProNo
    strMessage = "Please reply to this message with LOAD CONFIRMED (or similar text) in the message body." _
    & vbCrLf & vbCrLf & "Thank You," & vbCrLf & "Bryan"
    blnEditMail = True

    DoCmd.SendObject acSendReport, strReportName, acFormatSNP, strRecipient, , , strSubject, strMessage, blnEditMail
    Exit Sub

    ErrHandler:
    If Err.Number = 2501 Then
    'E-mail cancelled - just ignore the error
    Else
    'Other error - inform user
    MsgBox Err.Description, vbExclamation
    End If
    End Sub
    Bryan,
    Not the smartest critter on the glacier. . .
    . . .but I'm persistent (does that count?)

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Invalid use of Null (Msg) (2002 SP-2)

    Before the line strRecipient = Me.CarrierName, insert code like this:

    If IsNull(Me.CarrierName) Then
    MsgBox "You must first select a carrier", vbExclamation
    Me.CarrierName.SetFocus
    Exit Sub
    End If

    If there are more required fields, you can use similar code for those.

  3. #3
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Invalid use of Null (Msg) (2002 SP-2)

    Instead of handling it as an error you could also explicitly test for the condition yourself, before the code that sends the email
    <pre>if isnull(me.carriername) then
    msgbox("You must first select a carrier.")
    me.carriername.setfocus
    exit sub
    end if
    </pre>

    Regards
    John



  4. #4
    5 Star Lounger bfxtrfcmgr's Avatar
    Join Date
    Aug 2002
    Location
    Fresno, California, USA
    Posts
    995
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Re: Invalid use of Null (Msg) (2002 SP-2)

    Hans:

    Thanks for the reply. I had tried a number of ways in the ErrHandler and then finally tried something similar to your suggestion, but got lost in how to format the "If IsNull" statement. I have tried your suggestion, but am getting a "Compile Error: Method or data member not found" at SetFocus. Here is the (partial) code"

    Dim strReportName As String
    Dim strRecipient As String
    Dim strSubject As String
    Dim strMessage As String
    Dim blnEditMail As Boolean

    strReportName = "rptLoadConfirmSingleEmail"
    'Check to see that a carrier has been selected
    If IsNull(Me.CarrierName) Then
    MsgBox "You must first designate a carrier.", vbExclamation
    Me.CarrierName.<span style="background-color: #FFFF00; color: #000000; font-weight: bold">SetFocus</span hi>
    Exit Sub
    End If
    strRecipient = Me.CarrierName
    strSubject = "Load Confirm Attached for PRO# " & Me.ProNo
    strMessage = "Please reply to this message with LOAD CONFIRMED (or similar text) in the message body." _
    & vbCrLf & vbCrLf & "Thank You," & vbCrLf & "Bryan"
    blnEditMail = True

    Your assistance greatly appreciated.
    Bryan,
    Not the smartest critter on the glacier. . .
    . . .but I'm persistent (does that count?)

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Invalid use of Null (Msg) (2002 SP-2)

    Perhaps the control bound to the CarrierName field has a different name (in fact, many experts recommend to make the name and control source different). You need to use the name of the control. If that doesn't solve it, what is CarrierName?

  6. #6
    5 Star Lounger bfxtrfcmgr's Avatar
    Join Date
    Aug 2002
    Location
    Fresno, California, USA
    Posts
    995
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Re: Invalid use of Null (Msg) (2002 SP-2)

    <img src=/S/blush.gif border=0 alt=blush width=15 height=15>
    In design view it displays "CarrierName", but this is not a TextBox, it's a ComboBox. So, it's "real" name is ComboCarrierName. <img src=/S/dizzy.gif border=0 alt=dizzy width=15 height=15>

    "ComboCarrierName" (no quotes) works just fine.

    Thanks for another lesson learned (and hopefully not forgotten.
    Bryan,
    Not the smartest critter on the glacier. . .
    . . .but I'm persistent (does that count?)

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Invalid use of Null (Msg) (2002 SP-2)

    OK, glad it worked. Explanation: you have a control (combo box in this case) named ComboCarrierName bound to the field named CarrierName. For most purposes, it doesn't matter whether you test the control or the field for being Null: IsNull(Me.CarrierName) and IsNull(Me.ComboCarrierName) will return the same value. But you can only set focus to a control, not to a field. Me.CarrierName.SetFocuse causes an error since SetFocus is not a method of a field.

  8. #8
    5 Star Lounger bfxtrfcmgr's Avatar
    Join Date
    Aug 2002
    Location
    Fresno, California, USA
    Posts
    995
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Re: Invalid use of Null (Msg) (2002 SP-2)

    John:

    Very much appreciate your input/code. Please see msg string.
    Bryan,
    Not the smartest critter on the glacier. . .
    . . .but I'm persistent (does that count?)

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Invalid use of Null (Msg) (2002 SP-2)

    I think the reply I posted in the meantime corresponds to your question, but if you would like more info, don't hesitate to ask.

  10. #10
    5 Star Lounger bfxtrfcmgr's Avatar
    Join Date
    Aug 2002
    Location
    Fresno, California, USA
    Posts
    995
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Re: Invalid use of Null (Msg) (2002 SP-2)

    Hans:

    [EDIT] I was entering this when you replied.
    If I may be so bold, and to perhaps gather some knowledge here.
    Bryan,
    Not the smartest critter on the glacier. . .
    . . .but I'm persistent (does that count?)

  11. #11
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Invalid use of Null (Msg) (2002 SP-2)

    To find out the name of a control you need to look at its name property in the properties box. The name property is in the other group.

    Just because you have a combo box does not guarantee that its name will be combosomething. It depends on how you created it.
    Regards
    John



  12. #12
    5 Star Lounger bfxtrfcmgr's Avatar
    Join Date
    Aug 2002
    Location
    Fresno, California, USA
    Posts
    995
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Re: Invalid use of Null (Msg) (2002 SP-2)

    John:

    Thanks again for your input. Amazingly enough, I did manage to look up the name in the properties box this time. Some of the controls are named "Combo..." and others are named "Cmb..." (which really gets interesting when others (command buttons) are "Cmd..."). This little journey has revealed a number of things to me, not the least of which is comprehensive naming conventions. Having a greater understanding of code would be helpful in avoiding some "simple" problems (if only in the difference between calling an entry vs. calling a control). Oh well, onward and upward!

    Thanks!
    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> It's Guiness time!
    Bryan,
    Not the smartest critter on the glacier. . .
    . . .but I'm persistent (does that count?)

  13. #13
    5 Star Lounger bfxtrfcmgr's Avatar
    Join Date
    Aug 2002
    Location
    Fresno, California, USA
    Posts
    995
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Re: Invalid use of Null (Msg) (2002 SP-2)

    In the code provided in <post#=332508>post 332508</post#> ; is there some way to have it fire when a form is closed?

    I am using similar code in frmOrderNew to e-mail a confirmation that I have received the order. I would like for this to occur when I close the form (rather than taking the risk of forgetting to select a cmdbtn). This way the confirmation will always be sent whenever a new order is entered (I would retain the cmdbtn in frmOrderDetail in case I need to re-send the confirmation).The frmOrderNew already has the following code in the BeforeUpdate event:

    Private Sub Form_BeforeUpdate(Cancel As Integer)

    'Assigns new Pro# to order when form is closed.

    Dim dbs As DAO.Database, rs As DAO.Recordset
    Dim lngProNo As Long
    Set dbs = CurrentDb
    Set rs = dbs.OpenRecordset("tblProNoControl")
    rs.Edit
    rs!NextAvailableProNo = rs!NextAvailableProNo + 1
    lngProNo = rs!NextAvailableProNo
    rs.Update
    ProNo = lngProNo
    Set rs = Nothing
    Set dbs = Nothing
    End Sub

    Hope I'm not getting too far off subject.
    Bryan,
    Not the smartest critter on the glacier. . .
    . . .but I'm persistent (does that count?)

  14. #14
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Invalid use of Null (Msg) (2002 SP-2)

    What I would do is put a "Close" command button on the form, and call the code in the On Click event of the form. And I would take away the standard ways to close the form, so that the user MUST use the command button to close it. See (for example) <post#=94249>post 94249</post#> for a way to prevent the user from closing the form except using the command button.

  15. #15
    5 Star Lounger bfxtrfcmgr's Avatar
    Join Date
    Aug 2002
    Location
    Fresno, California, USA
    Posts
    995
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Re: Invalid use of Null (Msg) (2002 SP-2)

    Uh. . .

    I believe I have now mastered the art of complicating the most simple matters! (The really sad thing is that I spend about an hour trying to figure out how to combine the code in the AfterUpdate event).

    Thank you! <img src=/S/blush.gif border=0 alt=blush width=15 height=15>
    Bryan,
    Not the smartest critter on the glacier. . .
    . . .but I'm persistent (does that count?)

Page 1 of 2 12 LastLast

Posting Permissions

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