SMTP Emailing - Ostrosoft With Variable Error

  • Thread starter bhipwell via AccessMonster.com
  • Start date
B

bhipwell via AccessMonster.com

This has been driving me nuts. I am receiving an "Object variable or With
block variable" error on this code. It seems if I reload the code, it will
work. Any touching of it, however, smacks me with the error. Here is the
entire code on the form. Please help! Also, I need a way of simply
attaching a file located in my C drive, any help on this would be a bonus.

Option Compare Database

Dim WithEvents oSMTP As OSSMTP.SMTPSession

Private Sub cmdSend_Click()
txtStatus = ""
With oSMTP
'connection
'ERROR POPS UP HERE!
.Server = txtServer
'message
.MailFrom = txtMailFrom
.SendTo = txtSendTo
.MessageSubject = txtMessageSubject
.MessageText = txtMessageText
'send email
txtStatus.SetFocus
.SendEmail
End With
End Sub

Private Sub Form_Load()
Set oSMTP = New OSSMTP.SMTPSession
txtServer = "localhost"
txtMailFrom = "info"
txtSendTo = "test"
txtMessageSubject = "test"
txtMessageText = "some text"
End Sub

Private Sub Form_Unload(Cancel As Integer)
Set oSMTP = Nothing
End Sub

Private Sub oSMTP_ErrorSMTP(ByVal Number As Integer, Description As String)
txtStatus = txtStatus & "Error " & Number & ": " & Description & vbCrLf
txtStatus.SelStart = Len(txtStatus)
End Sub

Private Sub oSMTP_StatusChanged(ByVal Status As String)
txtStatus = txtStatus & oSMTP.Status & vbCrLf
txtStatus.SelStart = Len(txtStatus)
End Sub

B
 
G

Guest

Your variables don't appear to be declared anywhere... this will cause you
grief (as you have discovered). Either declare them globally (yuck) or
declare them locally to a sub and pass them to your send function.

Damian.
 
B

bhipwell via AccessMonster.com

Can you provide a little sample code? It has been a long while since I have
had to do this. Thanks!



Damian said:
Your variables don't appear to be declared anywhere... this will cause you
grief (as you have discovered). Either declare them globally (yuck) or
declare them locally to a sub and pass them to your send function.

Damian.
This has been driving me nuts. I am receiving an "Object variable or With
block variable" error on this code. It seems if I reload the code, it will
[quoted text clipped - 47 lines]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top