User defined type not defined

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dsperry101 via AccessMonster.com

    #1

    User defined type not defined

    Hello,
    I have been working with visual basic for a while but this is something I
    have never understood.
    I have some code in a VB6 application that sends email using Winsock and
    works great.
    I am trying to incorporate the code in Access 2000 . I inserted the
    activex control "Microsoft Winsock control (SP6) and it shows up on the form.
    When I ran the form I get "object variable with block not set" on the line
    "Winsock1.Local Port = 0", I added the "Set winsock1 = ActiveXCtl5.Obj ect".
    Now I get "User defined type not defined." I don't get any errors when I
    compile . The code is below. Can anyone enlighten me ?

    Dim winsock1 As Winsock

    Sub SendEmail(MailS erverName As String, _
    FromName As String, _
    FromEmailAddres s As String, _
    ToName As String, _
    ToEmailAddress As String, _
    EmailSubject As String, _
    EmailBodyOfMess age As String)
    'added next line stops object variable with block not set
    ' but then get "user defined type not defined
    Set winsock1 = ActiveXCtl5.Obj ect

    Winsock1.LocalP ort = 0 ' Must set local port to 0 (Zero) or you can only
    send 1 e-mail pre program start

    If Winsock1.State = sckClosed Then ' Check to see if socket is closed
    DateNow = Format(Date, "dd Mmm YYYY")
    first = "mail from:" & Chr(32) & FromEmailAddres s & vbCrLf ' Get who's
    sending E-Mail address
    Second = "rcpt to:" & Chr(32) & "<" & ToEmailAddress & ">" & vbCrLf ' Get
    who mail is going to
    Third = "Date:" & Chr(32) & DateNow & vbCrLf ' Date when being sent
    Fourth = "From:" & Chr(32) & FromName & vbCrLf ' Who's Sending
    Fifth = "To:" & Chr(32) & ToName & vbCrLf ' Who it going to
    Sixth = "Subject:" & Chr(32) & EmailSubject & vbCrLf ' Subject of E-
    Mail
    Seventh = EmailBodyOfMess age + vbCrLf ' E-mail message body
    Ninth = "dans emailer" & vbCrLf ' What program sent the e-mail,
    customize this
    Eighth = Fourth + Third + Ninth + Fifth + Sixth ' Combine for proper
    SMTP sending

    Winsock1.Protoc ol = sckTCPProtocol ' Set protocol for sending
    Winsock1.Remote Host = MailServerName ' Set the server address
    Winsock1.Remote Port = 25 ' Set the SMTP Port
    Winsock1.Connec t ' Start connection

    WaitFor ("220")
    Winsock1.SendDa ta ("HELO dsperry.dayton-phoenix.com" + vbCrLf)

    WaitFor ("250")
    Winsock1.SendDa ta (first)

    WaitFor ("250")
    Winsock1.SendDa ta (Second)

    WaitFor ("250")
    Winsock1.SendDa ta ("data" + vbCrLf)

    WaitFor ("354")
    Winsock1.SendDa ta (Eighth + vbCrLf)
    Winsock1.SendDa ta (Seventh + vbCrLf)
    Winsock1.SendDa ta ("." + vbCrLf)

    WaitFor ("250")
    Winsock1.SendDa ta ("quit" + vbCrLf)

    WaitFor ("221")
    Winsock1.Close
    Else
    MsgBox (Str(Winsock1.S tate))
    End If
    End Sub

    Sub WaitFor(Respons eCode As String)
    Start = Timer ' Time event so won't get stuck in loop
    While Len(Response) = 0
    Tmr = Start - Timer
    DoEvents ' Let System keep checking for incoming response
    **IMPORTANT**
    If Tmr 50 Then ' Time in seconds to wait
    MsgBox "SMTP service error, timed out while waiting for response"
    Exit Sub
    End If
    Wend
    While Left(Response, 3) <ResponseCode
    DoEvents
    If Tmr 50 Then
    MsgBox "SMTP service error, impromper response code. Code should
    have been: " + ResponseCode + " Code recieved: " + Response
    Exit Sub
    End If
    Wend
    Response = "" ' Sent response code to blank **IMPORTANT**
    End Sub

    Private Sub Winsock1_DataAr rival(ByVal bytesTotal As Long)
    Winsock1.GetDat a Response ' Check for incoming response *IMPORTANT*
    End Sub

    --
    Danny C. Sperry

    Message posted via AccessMonster.c om


  • Rich P

    #2
    Re: User defined type not defined

    Greetings,

    I have never had much luck with winsock, wininet controls (I can't even
    remember what they are called). But I did write a few apps using the
    wininet dll for ftp stuff. That sort of worked - for ftp stuff. For
    emaiing, you could use the Outlook client, but the problem with that is
    the Outlook security. You get security prompts for everything when
    accessing Outlook externally (like from Access). I used to have a
    LotusNotes client, and that worked OK - but that was several years ago.
    If you want to interface directly with the email server - you may try
    some low level api code (which I don't know the api functions off hand -
    try googling email api). But I am just finishing up an email client in
    VB.Net which is working well with the .Net framework. My advice for
    email apps is to do it in .Net. Much easier and more reliable. .Net
    has all the api's built in, and you get the dropdown intellisense for
    all the required methods/properties - that is why .Net is so much easier
    that VBA for this kind of stuff - it is all built in - plus - way more
    extensive help files.

    Rich

    *** Sent via Developersdex http://www.developersdex.com ***

    Comment

    • Salad

      #3
      Re: User defined type not defined

      Rich P wrote:
      Greetings,
      >
      I have never had much luck with winsock, wininet controls (I can't even
      remember what they are called). But I did write a few apps using the
      wininet dll for ftp stuff. That sort of worked - for ftp stuff. For
      emaiing, you could use the Outlook client, but the problem with that is
      the Outlook security. You get security prompts for everything when
      accessing Outlook externally (like from Access).
      I recommend ClickYes.
      Express ClickYes is a tiny program that sits in the System Tray and clicks the Yes button on behalf of you, when Outlook's Security Guard opens prompt dialog saying that a program is trying to send an email with Outlook or access its address book.

      Comment

      Working...