If Then statement doesn't recognise the value in combobox (sending an email)

bignate

Registered User.
Local time
Today, 06:45
Joined
Aug 28, 2013
Messages
34
Hi, I have used the code below to send an email automatically when a new record has been created. However I recently added the If Then statement to the code as you can see. The problem is that the email wont send because it says "There must be at least one name or distribution list in the To Cc or Bcc box". It is most likely saying this because it doesn't recognise "IT" in the txtDeparment combobox. How can I get it to recognise IT in the department combobox? The reason I am using an If Then is because I will make it send to different email addresses depending on what is in txtDepartment by using ElseIf

Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
With MailOutLook
.BodyFormat = olFormatRichText
If Me.txtDepartment = "IT" Then
.To = "my email"
End If
.Subject = "hi"
.HTMLBody = "hi"
.send
End With

Thanks
 
have you tried debugging this to see what value is in Me.txtDepartment
If you put a break on that line, you can step through it to inspect the value

David
 
Thank you.
I just put the break point in and it said the value is null. I then realised that it was null because I had the code after DoCmd.GoToRecord acActiveDataObject, , acNewRec
So txtDeperaent was actually null

I changed it so that DoCmd.GoToRecord acActiveDataObject, , acNewRec was after the code
 

Users who are viewing this thread

Back
Top Bottom