troubleshooting Question

invalid use of null

Avatar of chicka616
chicka616 asked on
Microsoft Access
22 Comments1 Solution420 ViewsLast Modified:
I am unsure of why this only works HALF the time..

I get the error "invalid use of null" even though there is an e-mail address in the field.
Of course if this happens, it does not add the address to the table, nor is the data cleared afterwards.

It is not consistant whatsoever.. sometimes it works, sometimes it doesn't.
Any suggestions?


Private Sub Command6_Click()
On Error GoTo Err_Command6_Click

Dim TemplateLocation As String


TemplateLocation = DLookup("[TemplateLocation]", "CampaignInfo", "[CampaignName]= Forms!CampaignMenu.CampaignList")
   

   
   Dim checksent As Variant
   Dim myOlApp As Outlook.Application
   Dim MyItem As Outlook.MailItem
   Set myOlApp = CreateObject("Outlook.Application")
   Set MyItem = myOlApp.CreateItemFromTemplate(TemplateLocation)

    MyItem.SentOnBehalfOfName = "OTeam"
    MyItem.To = Me.Text78
    MyItem.Display
    checksent = "true"
    Me.Parent.Controls("Check75").Value = checksent

' This is where access decides if it has to add the current email address to Emails table.
' First case, it already exists in the table, so do nothing

If DCount("*", "Emails", "CustomerID= '" & CustomerID.Value & "' And Email = '" & Text78.Value & "'") > 0 Then
    Me.Text78 = Me.Text78
Else

' Second case, email doesn't exist in the table, so add it.
' Inserting e-mail into e-mail table

    Dim conDatabase2 As New ADODB.Connection
    Dim strSQL2 As String
    Dim CustomerID2 As String
    Dim email2 As String

    CustomerID22 = Me.CustomerID
    email2 = Me.Text78
    Set conDatabase2 = CurrentProject.Connection
    strSQL2 = "INSERT INTO [Emails] (CustomerID, Email) values ('" & CustomerID2 & "', '" & email2 & "')"
    conDatabase2.Execute strSQL2

    conDatabase2.Close

End If


Me.Text78 = ""

Exit_Command6_Click:
    Exit Sub

Err_Command6_Click:
    MsgBox Err.Description
    Resume Exit_Command6_Click

End Sub
ASKER CERTIFIED SOLUTION
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Database Architect / Application Developer
Join our community to see this answer!
Unlock 1 Answer and 22 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 22 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros