Code fails, but then works!

  • Thread starter Thread starter DubboPete
  • Start date Start date
D

DubboPete

Hi all,

I have a bit of code which sends an email (Novell Groupwise). It
fails when I first click the command button, but once I hit the [END]
button for the error (as in End/Debug screen), and then click the
command button again, the darned thing works!

Can anybody see from the code below why it should fail at the first
attempt, but then work on the second attempt??

thanks in anticipation

<snip>

Dim StrWho As String
Dim StrFullname As String
Dim StrAmount As String
Dim StrNextDate As String

StrWho = Me.Text20 & "@gwahs.health.nsw.gov.au"
StrFullname = DLookup("[FIRSTNAME]", "TblMEMBERS", "[ID] = [Forms]!
[FrmPAYMENTS]![COMBO9]") & " " & DLookup("[SURNAME]", "TblMEMBERS",
"[ID] = [Forms]![FrmPAYMENTS]![COMBO9]")
StrAmount = Me.PAIDAMOUNT
StrNextDate = Me.NEXTDUE
DoCmd.SetWarnings False
DoCmd.OpenQuery "QrymkPayRecords"
DoCmd.SetWarnings True
Me.Text20 = DLookup("[FIRSTNAME]", "TblMEMBERS", "[ID] = [Forms]!
[FrmPAYMENTS]![COMBO9]") & "." & DLookup("[SURNAME]", "TblMEMBERS",
"[ID] = [Forms]![FrmPAYMENTS]![COMBO9]")
Me.Refresh


DoCmd.SendObject , , , StrWho, "", "", "Lotto Payment Receipt of
$" & StrAmount, , False, ""
MsgBox "A Lotto Receipt for $" & StrAmount & " has been emailed to
" & StrFullname
Combo9.SetFocus

</snip>

DubboPete
 
Hi Pete,

I reckon it fails because you are calculating your strWHO variable before
you are poplating text20 with the person's firstname dot surname. Therefore
when you click it a second time, the text box has been populated (from teh
time before) hence it works.

Move your strWHO = line to after the dlookup populating text20.

Damian.
 
Hi Pete,

I reckon it fails because you are calculating your strWHO variable before
you are poplating text20 with the person's firstname dot surname. Therefore
when you click it a second time, the text box has been populated (from teh
time before) hence it works.

Move your strWHO = line to after the dlookup populating text20.

Damian.



DubboPete said:
I have a bit of code which sends an email (Novell Groupwise). It
fails when I first click the command button, but once I hit the [END]
button for the error (as in End/Debug screen), and then click the
command button again, the darned thing works!
Can anybody see from the code below why it should fail at the first
attempt, but then work on the second attempt??
thanks in anticipation

Dim StrWho As String
Dim StrFullname As String
Dim StrAmount As String
Dim StrNextDate As String
StrWho = Me.Text20 & "@gwahs.health.nsw.gov.au"
StrFullname = DLookup("[FIRSTNAME]", "TblMEMBERS", "[ID] = [Forms]!
[FrmPAYMENTS]![COMBO9]") & " " & DLookup("[SURNAME]", "TblMEMBERS",
"[ID] = [Forms]![FrmPAYMENTS]![COMBO9]")
StrAmount = Me.PAIDAMOUNT
StrNextDate = Me.NEXTDUE
DoCmd.SetWarnings False
DoCmd.OpenQuery "QrymkPayRecords"
DoCmd.SetWarnings True
Me.Text20 = DLookup("[FIRSTNAME]", "TblMEMBERS", "[ID] = [Forms]!
[FrmPAYMENTS]![COMBO9]") & "." & DLookup("[SURNAME]", "TblMEMBERS",
"[ID] = [Forms]![FrmPAYMENTS]![COMBO9]")
Me.Refresh
DoCmd.SendObject , , , StrWho, "", "", "Lotto Payment Receipt of
$" & StrAmount, , False, ""
MsgBox "A Lotto Receipt for $" & StrAmount & " has been emailed to
" & StrFullname
Combo9.SetFocus

DubboPete- Hide quoted text -

- Show quoted text -

Hi Damian

Exactly as you thought, I moved the StrWho line to below
the ...=[firstname].[surname] line, and it worked perfectly!

many thanks mate!
 
Back
Top