Question : Runtime Error: 94 Invalid Use of Null

Hey everyone!

This code was working fine. I have tested it and it worked...it has worked for about a week now. I get an email the other day telling me there is an error with my Access DB. The error is in the subject of this post.

When I click debug on the error this is the line is highlights in yellow:

myuser_id = DLookup("user_id", "company_user", "username = """ & Replace(Trim(theUsername), vbCrLf, "") & """")

I assume myuser_id is not being populated with data.

The rest of the code is below:

<<--

Private Sub get_Emails(strEmailContents As String)
Dim strEmailBody As String
    'declare a variable to hold the email body text
    'if your field is not called contents, change this bit below
    strEmailBody = strEmailContents
   
    'stremail now holds the email body

'these are variables to show the email where the body "headers" are
usernamepos = 0

'these are variables to show where in the email body the actual values are
theUsername = ""

'this is a variable to show where we are in the email body
currentpos = 1

'look for the words "Username:" - this must be EXACLTY how it appears in the email
usernamepos = InStr(currentpos, strEmailBody, "Username: ")
currentpos = usernamepos

'we now know where all the headers are, so find the text inbetween them and assign them to the appropriate variables:
'ie the first name wiil be between First Name and Last Name

If usernamepos <> 0 Then
    fieldlen = Len("Username: ")
    theUsername = Mid(strEmailBody, usernamepos + fieldlen, usernamepos + fieldlen)
End If

Dim myuser_id As String
Dim username As String

myuser_id = DLookup("user_id", "company_user", "username = """ & Replace(Trim(theUsername), vbCrLf, "") & """")
mysupport_problem = "Automated username and password request."
mysupport_solution = "Username and password sent to participant by way of automated password retrieval system."
mysupport_tech = "SLJ"
mysupport_status = "1"

MsgBox "The username is:" + theUsername
MsgBox "The Length of the username is:" & Len(theUsername)
MsgBox "The User ID is: " + myuser_id
MsgBox "Support Problem is: " + mysupport_problem
MsgBox "Support Solution is: " + mysupport_solution
MsgBox "Support Tech is: " + mysupport_tech
MsgBox "Support Status is: " + mysupport_status

'Dim srtSQLInsert As String
strSQLInsert = "insert into [company_support] ([user_id],[support_problem],[support_solution],[support_tech],[support_status]) values('" & Trim(myuser_id) & "','" & Trim(mysupport_problem) & "','" & Trim(mysupport_solution) & "','" & Trim(mysupport_tech) & "','" & Trim(mysupport_status) & "')"

'this command actually runs the insert statement - uncomment it
DoCmd.SetWarnings (False)

'DoCmd.RunSQL Replace(Replace(strSQLInsert, Chr(10), ""), Chr(13), "")

DoCmd.SetWarnings (False)

End Sub
Private Sub Form_Open(Cancel As Integer)

Dim dbs As Database
Dim rst As DAO.Recordset

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Password Request Emails")

With rst
    If .RecordCount <> 0 Then
        Do While Not rst.EOF
            'procedure from button
            get_Emails (rst.Fields("Body"))
        rst.MoveNext
        Loop
    End If
End With

'deletes all the records in the linked outlook table
deleteoutlookpasswordtable = "Delete from [Password Request Emails]"

'this command runs the deletion of the outlook registrations new table
DoCmd.SetWarnings (False)

'DoCmd.RunSQL (deleteoutlookpasswordtable)

DoCmd.SetWarnings (False)

'DoCmd.Close

DoCmd.Quit ACSaveAll

End Sub

-->>

Any ideas.

Thanks,

Shawn.

Answer : Runtime Error: 94 Invalid Use of Null

Make the regular expression like this:

re.Pattern = "[^\w.]+"

This will remove ALL characters that are not-alphanumeric, or periods.  Are there any other characters that can be had in a username?
Random Solutions  
 
programming4us programming4us