1st Attempt at email - Only works Once?

PNGBill

Win10 Office Pro 2016
Local time
Tomorrow, 06:35
Joined
Jul 15, 2008
Messages
2,271
Hi Forum, access 2000

I found an email database on the forum and got it to work for me but I have to close the database and reopen to send a 2nd email:confused:

Here is the full code which includes the original.
I have yet to edit out any surplus code.

Can anyone spot where I need to alter the code to allow more then one 'click" of the button.:)
Even if you select a new record, the button won't work.
Only works Once when Database is opened.

Code:
Private Sub CmdEmailPointsBalance_Click()
    Dim varTo As Variant                    'Email Address
    Dim stText As String                    'Email Text
    Dim stSubject As String                 'Email Subject Line
    Dim strSQL As String                    'SQL String
    Dim PointsAvailable As Integer          'Available Club Points
    Dim MembID As String                    'Member ID
    Dim errLoop As Error
    
    MembID = Me.MemberID                    'set forms current Member ID to be variable value
    PointsAvailable = Me.txtPointsBalance   'Set Forms Points Available to Use as variable value
    
     On Error GoTo Err_CmdEmailPointsBalance_Click

  '  Dim stWhere As String       '-- Criteria for DLookup
  '  Dim varTo As Variant        '-- Address for SendObject
  '  Dim stText As String        '-- E-mail text
  '  Dim RecDate As Variant      '-- Rec date for e-mail text
  '  Dim stSubject As String     '-- Subject line of e-mail
  '  Dim stTicketID As String    '-- The ticket ID from form
  '  Dim stWho As String         '-- Reference to tblUsers
  '  Dim stHelpDesk As String    '-- Person who assigned ticket
  '  Dim strSQL As String        '-- Create SQL update statement
  '  Dim errLoop As Error

    '-- Combo of names to assign ticket to
  '  stWho = Me.cboAssignee
  '  stWhere = "tblUsers.strUserID = " & "'" & stWho & "'"
    '-- Looks up email address from TBLACCDET
    varTo = DLookup("[ADEmail]", "TBLACCDET", "[ADPK]=" & MembID)

    stSubject = ":: Member Club Points Balance ::"

  '  stTicketID = Format(Me.txtTicketID, "00000")
  '  RecDate = Me.txtDateReceived
    '-- Helpdesk employee who assigns ticket
  '  strHelpDesk = Me.cboReceivedBy.Column(1)

    stText = "Your Club Points Balance is " & PointsAvailable & ". " & Chr$(13) & Chr$(13) & _
             "This is an automated message. Please do not respond to this e-mail."

    'Write the e-mail content for sending to assignee
    DoCmd.SendObject , , acFormatTXT, varTo, , , stSubject, stText, -1

    'Set the update statement to disable command button
    'once e-mail is sent
  '  strSQL = "UPDATE tblHelpDeskTickets SET tblHelpDeskTickets.ysnTicketAssigned = -1 " & _
  '           "Where tblHelpDeskTickets.lngTicketID = " & Me.txtTicketID & ";"

'    On Error GoTo Err_Execute
'    CurrentDb.Execute strSQL, dbFailOnError
'    On Error GoTo 0

    'Requery checkbox to show checked
    'after update statement has ran
    'and disable send mail command button
 '   Me.chkTicketAssigned.Requery
 '   Me.chkTicketAssigned.SetFocus
 '   Me.cmdMailTicket.Enabled = False

    Exit Sub

'Err_Execute:

    ' Notify user of any errors that result from
    ' executing the query.
'    If DBEngine.Errors.Count > 0 Then
'        For Each errLoop In DBEngine.Errors
'            MsgBox "Error number: " & errLoop.Number & vbCr & _
'                   errLoop.Description
'        Next errLoop
'    End If

    Resume Next
    
Exit_CmdEmailPointsBalance_Click:
    Exit Sub

Err_CmdEmailPointsBalance_Click:
    MsgBox Err.Description
    Resume Exit_CmdEmailPointsBalance_Click

    

End Sub
 
Added Message Boxes and the code works fine right up until the DoCmd line.

In my :confused: I really don't understand what is happening at this stage.:confused:

How does access / system know this is an email to send?
 
Thanks SpentGeezer, Not sure how the link can help. Probably my ignorance is the problem.

Tried adding the enabled code but makes no diff.
The code that disables the control is remarked out in any case.

The sample databse also requires a re open of that database, to send and email to the same person, as well as reset of the flag, although the sample database will allow sending emails to other persons where as our database does not:confused:
 
Here is the sample database - does allow emails to different persons but not to the same person unless flag is reset (understandable) but also, database must be closed and opened again.
 

Attachments

Bill,

I am a bit stumped. I can email as many as I want (through Lotus Notes. You have not recieved them because I didn't click Send in Notes). The only thing I can suggest is removing the disabling of the button when the check box is ticked:

Private Sub chkTicketAssigned_AfterUpdate()

'Enable/disable Send Ticket command button
'if Ticket assigned checkbox is checked/unchecked

If Me.chkTicketAssigned = -1 Then
Me.cmdMailTicket.Enabled = False '------change to True
Else
Me.cmdMailTicket.Enabled = True
End If
End Sub

Maybe try enabling the button on the On Current property of the form...???
 
Thanks SpentGeezer,

I didn't use this code in my database.
The sample db opens a form on click and the on current event is the code you refer to.

For our database I have just used a Command Button on an existing form that has the data included already - some of it.

Most of the code is remarked out and I only used the cmdMailTicket_Click() code, less many remarked lines.

In my use, there is only the one button and no flag to update or reset.

When you test the code, you can send an email to person A and just reset the tick box and immediately send another email to that person - correct?

When I test the sample database I must restart to do this even though I have reset the tick box.
Resetting the tick box appears to enable the command button but when clicked, no email appears to be "sent" and the command button is disabled again.

Maybe this has something to do with our email, but why would restarting the database allow you to then send another email??:confused:

We use Outlook Express as our email client.

I just closed outlook express and reopened it but no difference.

Only shutting the database and restarting will allow a new email to be sent to the same person.:confused:
 
your code works fine with me.

Are you sure that outlook is actually sending the email? If you leave the email open without sending it, this might be causeing a problem.

Otherwise you need to debug your code and also explain exactly what is not working or exactly what is happening.
 
Thanks Darbid,
The email sends fine, first time.
Tested on our emails.

Have installed msgboxes in the code and it returns all the data correctly, right up until the
Code:
 DoCmd.SendObject , , acFormatTXT, varTo, , , stSubject, stText, -1
Line.

Found this on the www that refers to issues with access 2000 and SendObject
http://database.itags.org/ms-access-database/191381/
 
If you get another opinion that your code is ok, in your position I would be doing my own code to send emails instead of using access's function.
 
Issue resolved:)

Because we had made pc changes I must have reinstalled Office 2000 and not reinstalled sp2 & sp3.

Just did that and Wala, I can resend emails as many times as I like.

just an Office Service Pack issue.

Thanks for the support. Much appreciated.

Have crossed another Bridge with now being able to email direct from access.
This will keep me busy for a while adding more command buttons all over the place.

Next I need to play with the lebans code to direct a .pdf print to a named file as 2000 doesn't allow this as 2007 and onwards does.

Thanks again:)
 
THat Lebans code is awesome. I use it in all my databases to print to PDF. It is pretty straight forward.
 
THat Lebans code is awesome. I use it in all my databases to print to PDF. It is pretty straight forward.

Hi SpentGeezer,

Just downloaded the Lebans Code.

If you are able to check a new thread I will raise regarding Lebans and Access 2000.

Thanks,
Bill
 
Hi SpentGeezer,

Just downloaded the Lebans Code.

If you are able to check a new thread I will raise regarding Lebans and Access 2000.

Thanks,
Bill


DONE!!!!!!!!!!!!! (10 Characters)
 

Users who are viewing this thread

Back
Top Bottom