Email Button

LinBee

LB2008
Local time
Today, 15:40
Joined
Oct 23, 2008
Messages
7
I have created a button with code attached to send email to users when they have been set up on our system but everytime I run the code I get an eror message.
Compile error

Argument not optional

and the word Post is highlighted

here is my code.

Private Sub Command108_Click()
On Error GoTo Err_Command108_Click
Dim SendTo As String, MySubject As String, MyMessage As String
SendTo = Recepirnt[EMAIL="Recepirnt@hotmail.com"]@hotmail.com[/EMAIL]
MySubject = Me.Fname & " " & Me.Sname
MyMessage = " I have set up " & Fname & " " & Sname & " on lid no " & Uname & " password is x" & vbCtrLf & vbCrLf & "She is " & Post & " Based at " & Section

DoCmd.SendObject acSendNoObject, , , SendTo, , , MySubject, MyMessage, True
Exit_Command108_Click:
Exit Sub
Err_Command108_Click:
MsgBox Err.Description
Resume Exit_Command108_Click

End Sub

PLEASE PLEASE HELP
 
You need quotes round your email address:
Code:
SendTo = "Recepirnt@hotmail.com"

hth
Chris
 
Welcome to the forum by the way.
Chris
 
I have quotes outside the email adress it is only when I was editing the address for psoting that quotes got deleted. In the actual code the email does have quotes.

Thanks I hope I will get a lot out of the forum.
 
Last edited:
Well...the problem here the word Post which I assume is the name of one of your Controls within Form. Post is a Keyword and is used in VBA. Post is a Method of the PostItem Object and therefore can not be used in the fashion you are using it.

This is all to common a problem where developers use keywords for Table Field names, Form or Report Control Names, and for Constants and or Variables. This should be avoided at all costs.

Date and Name are also keywords and commonly used for names or variables. If there is to much of this sort of thing within your Database then things can get catastrophic and you will not get a warning when Forms refuse to open to run or design view. They just become corrupt and you have to start all over again. There are a lot of keywords used in VBA and MS-Access altogether. If you are not sure about a word you are using then enter it into the VBA Editor, highlight it, then hit the F1 key to see if there if Help. If there is then use something else.

Try to be unique with your Field, Control, or Variable names. Table names should start with tbl (tblCustomers), Table Field Names with fld (fldCustmerID), Form names with frm (frmCustomers), Form Control with an abbreviation of the Control Type (txtName, cboName, lblName, etc.), String variables with str (strName), Integer Variables with int (intName), etc, etc.

In your case you can probably get away with Me.Post but if I were you, I would change the name to txtPost and use Me.txtPost.

Code:
MyMessage = " I have set up " & Me.txtFname & " " & Me.txtSname & " on lid no " & _
               Me.txtUname & " password is x" & vbCtrLf & vbCrLf & "She is " & _
               Me.[COLOR="Blue"][B]txtPost[/B][/COLOR] & " Based at " & Me.txtSection

Personally, I also avoid spaces in Table, Field, Form, and Control names. Rather Than Customer Name I would use CustomerName. Don't have to bother with brackets all the time and relying on Access to set up the Underscore character ( _ ) for Form Control names.

Anyways....that's my two-bits

.
 
Last edited:
Thanks I tried txtPost, txtpost and txtjb still getting same message. Still at sea!!
 
Copy and paste us the entire piece of code the way you now have it.
 
Also, is Option Explicit specified because vbCtrLf is a spelling error?
Chris
 
Thanks everyone for your helpful responses, but as per advice I changed one of the field names from section to txtSection and it worked.

Thanks a million:D
 
In the one string alone you had used two keywords.

Now would be a excellent time to go through the rest of your Database code and see if more of this sort of thing is lurking there.

If you get into the habit of prefixing your names with the abbreviation of what they are then you should never run into this problem and save you even larger headaches down the road.

.
 

Users who are viewing this thread

Back
Top Bottom