How to Attach the File in a Email using VB & Access

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ttamilvanan81
    New Member
    • Mar 2007
    • 35

    How to Attach the File in a Email using VB & Access

    Hai, am using the Email function with Attachments in Vb and Access Forms. The Emial function is working. Then how to attach the file with my mail. there is any Browse control is there.

    anybody know pls let me know.

    By

    Tamilvanan
  • vijaydiwakar
    Contributor
    • Feb 2007
    • 579

    #2
    Originally posted by ttamilvanan81
    Hai, am using the Email function with Attachments in Vb and Access Forms. The Emial function is working. Then how to attach the file with my mail. there is any Browse control is there.

    anybody know pls let me know.

    By

    Tamilvanan
    try this code
    Code:
     
    Private Sub Form_Load()
    Set OLApp = CreateObject("Outlook.Application")
            Set MyItem = OLApp.CreateItem(olMailItem)
            
            txtInsertFile.Text = "c:\ReadMe.txt"
            MyItem.To = "xxx@gmail.com"
            
            MyItem.Subject = "Attach file"
            MyItem.Body = "read this file "
            Set MyAttachments = MyItem.Attachments
            MyAttachments.Add txtInsertFile.Text
            MyItem.Send
    End Sub

    Comment

    • ttamilvanan81
      New Member
      • Mar 2007
      • 35

      #3
      Originally posted by vijaydiwakar
      try this code
      Code:
       
      Private Sub Form_Load()
      Set OLApp = CreateObject("Outlook.Application")
              Set MyItem = OLApp.CreateItem(olMailItem)
              
              txtInsertFile.Text = "c:\ReadMe.txt"
              MyItem.To = "xxx@gmail.com"
              
              MyItem.Subject = "Attach file"
              MyItem.Body = "read this file "
              Set MyAttachments = MyItem.Attachments
              MyAttachments.Add txtInsertFile.Text
              MyItem.Send
      End Sub

      Hai, I am Trying to attach a file using your code. But i have the error message, while run this code. The error message was given below.

      "Run-time error '2185':
      You can't reference a property or method for a control unless the control has the focus."

      Thanks

      Tamilvanan

      Comment

      • vijaydiwakar
        Contributor
        • Feb 2007
        • 579

        #4
        Originally posted by ttamilvanan81
        Hai, I am Trying to attach a file using your code. But i have the error message, while run this code. The error message was given below.

        "Run-time error '2185':
        You can't reference a property or method for a control unless the control has the focus."

        Thanks

        Tamilvanan
        this may be due to some another reason
        mycode is perfect

        Comment

        • ttamilvanan81
          New Member
          • Mar 2007
          • 35

          #5
          Originally posted by vijaydiwakar
          this may be due to some another reason
          mycode is perfect

          I need to Browse and select the file, and attach that file in the Email using Ms-Access 2003 and OutLook 2003.

          Can you know how to Browse the file, let me know.
          In the previous code, in my system isn't have the activex control properly. So thats why that is not working.

          Kindly, let me know how to browse and attach the file please....

          Thanks,
          Tamilvanan

          Comment

          • iburyak
            Recognized Expert Top Contributor
            • Nov 2006
            • 1016

            #6
            In Visual Basic References check
            Microsoft Outlook 11.0 Object Library

            before running code above.


            Good Luck.

            Comment

            • ttamilvanan81
              New Member
              • Mar 2007
              • 35

              #7
              Hai.

              Thanks for your replies.

              I need to Browse the File. I need not to set the default file location and attach the file.Like this

              txtInsertFile.T ext = "c:\ReadMe. txt"

              I need like this. If we will click the Browse button, the file window will be opened, and we select the Driver(C: or D: or E: ). Then we select the Directories and filename.Then we click the open, the whole file path was stored in a Text box.

              This method i need it. Can you know how to do this.

              Please let me know.

              Thanks
              Tamilvanan

              Comment

              • vijaydiwakar
                Contributor
                • Feb 2007
                • 579

                #8
                Originally posted by ttamilvanan81
                Hai.

                Thanks for your replies.

                I need to Browse the File. I need not to set the default file location and attach the file.Like this

                txtInsertFile.T ext = "c:\ReadMe. txt"

                I need like this. If we will click the Browse button, the file window will be opened, and we select the Driver(C: or D: or E: ). Then we select the Directories and filename.Then we click the open, the whole file path was stored in a Text box.

                This method i need it. Can you know how to do this.

                Please let me know.

                Thanks
                Tamilvanan
                for that use directory ctrl or u may use commandialogbox a comman ctrl of ms windows
                Last edited by vijaydiwakar; Apr 2 '07, 01:16 PM. Reason: mispelled

                Comment

                • ttamilvanan81
                  New Member
                  • Mar 2007
                  • 35

                  #9
                  Hai.
                  I am Try to drag and drop that control But i cant.
                  Actually in Access forn Design view, Normal Toolbox does not contain that controls. So am go to click the more controls button. Then am select the Microsoft Common Dialog Control, Version 6.0 . Other Two Controls are not displayed.

                  The Error message displays, while select the control. The Erro Message is.

                  you don't have the license required to use this ActiveX control.
                  You tried to open a form containing an OLE object or an ActiveX control or you tried to create an ActiveX control. To obtain the appropriate license, contact the company that provides the licensed OLE object or ActiveX control.



                  So how to Rectify this error. Why this Error was Occured, while drag and drop the control.

                  Please post me the detail.

                  Thanks,

                  Tamilvanan
                  Last edited by ttamilvanan81; Apr 2 '07, 01:37 PM. Reason: Miss Spelling

                  Comment

                  • iburyak
                    Recognized Expert Top Contributor
                    • Nov 2006
                    • 1016

                    #10
                    Is it possible that you are not a local admin on your computer?
                    Visual Basic is writing something on your C drive first time you use an OCX. If you don't have rights to edit your C drive it could happen.

                    If you would be able to put Dialog Box control on your form use following code to load file text into a textbox which should be MultiLine = True and have ScrollBars.

                    [PHP]Dim sFileName As String, NextLine As String
                    Dim FH As Long

                    With CommonDialog1
                    .CancelError = True
                    .Filter = "All Files(*.*)|*.*| Text Files(*.txt)|*. txt"
                    .FilterIndex = 2
                    .InitDir = "I use this property when I have default directory standard or in many cases I save last used path"
                    .ShowOpen

                    sFileName = .FileName
                    End With

                    FH = FreeFile()

                    Open sFileName For Input Access Read Shared As #FH

                    Do Until EOF(FH)
                    Line Input #FH, NextLine
                    Text1.Text = Text1.Text & NextLine & vbCrLf
                    Loop

                    Close #FH[/PHP]

                    Comment

                    • ttamilvanan81
                      New Member
                      • Mar 2007
                      • 35

                      #11
                      Originally posted by iburyak
                      Is it possible that you are not a local admin on your computer?
                      Visual Basic is writing something on your C drive first time you use an OCX. If you don't have rights to edit your C drive it could happen.

                      If you would be able to put Dialog Box control on your form use following code to load file text into a textbox which should be MultiLine = True and have ScrollBars.

                      [PHP]Dim sFileName As String, NextLine As String
                      Dim FH As Long

                      With CommonDialog1
                      .CancelError = True
                      .Filter = "All Files(*.*)|*.*| Text Files(*.txt)|*. txt"
                      .FilterIndex = 2
                      .InitDir = "I use this property when I have default directory standard or in many cases I save last used path"
                      .ShowOpen

                      sFileName = .FileName
                      End With

                      FH = FreeFile()

                      Open sFileName For Input Access Read Shared As #FH

                      Do Until EOF(FH)
                      Line Input #FH, NextLine
                      Text1.Text = Text1.Text & NextLine & vbCrLf
                      Loop

                      Close #FH[/PHP]

                      Hai,

                      I can't able to put the Dialog Box control in my form. So that am asking this question.

                      I need to Rectify the errors, while am try to put the control in my Access Form.

                      The Error Message Is :
                      you don't have the license required to use this ActiveX control.
                      You tried to open a form containing an OLE object or an ActiveX control or you tried to create an ActiveX control. To obtain the appropriate license, contact the company that provides the licensed OLE object or ActiveX control.


                      This have any difference for Vb Forms and Access Forms.

                      If, what's the difference between Vb Form and Access Form.

                      Becaouse, I am trying this mail functionality using Ms-Access Form only. But, i think it have the same characteristics as Vb Form.

                      Any ActivX control or Components need to install for this problem?

                      Comment

                      • ttamilvanan81
                        New Member
                        • Mar 2007
                        • 35

                        #12
                        Originally posted by iburyak
                        Is it possible that you are not a local admin on your computer?
                        Visual Basic is writing something on your C drive first time you use an OCX. If you don't have rights to edit your C drive it could happen.

                        If you would be able to put Dialog Box control on your form use following code to load file text into a textbox which should be MultiLine = True and have ScrollBars.

                        [PHP]Dim sFileName As String, NextLine As String
                        Dim FH As Long

                        With CommonDialog1
                        .CancelError = True
                        .Filter = "All Files(*.*)|*.*| Text Files(*.txt)|*. txt"
                        .FilterIndex = 2
                        .InitDir = "I use this property when I have default directory standard or in many cases I save last used path"
                        .ShowOpen

                        sFileName = .FileName
                        End With

                        FH = FreeFile()

                        Open sFileName For Input Access Read Shared As #FH

                        Do Until EOF(FH)
                        Line Input #FH, NextLine
                        Text1.Text = Text1.Text & NextLine & vbCrLf
                        Loop

                        Close #FH[/PHP]
                        Hai,
                        Thank you very much of your reply.
                        Am used ur code. But that have occured error while running those code.
                        The error message was.

                        Run-time error '424':
                        Object required

                        This error occured at the following line.
                        .CancelError = True

                        Can you know why this error could be occured.
                        If you know, pls let me know.

                        Thanks
                        Tamilvanan

                        Comment

                        • vijaydiwakar
                          Contributor
                          • Feb 2007
                          • 579

                          #13
                          Originally posted by ttamilvanan81
                          Hai,
                          Thank you very much of your reply.
                          Am used ur code. But that have occured error while running those code.
                          The error message was.

                          Run-time error '424':
                          Object required

                          This error occured at the following line.
                          .CancelError = True

                          Can you know why this error could be occured.
                          If you know, pls let me know.

                          Thanks
                          Tamilvanan
                          see this is a facility given expolicitly by Microsoft to tress Cancel Button click
                          u may avoid this line but for that ur code must be prepared for handling cancel btn
                          have u placed Commandialog box on ur form?
                          if yes check its name is same as that of commandialogebo x1
                          which u've used in With bolck

                          Comment

                          • ttamilvanan81
                            New Member
                            • Mar 2007
                            • 35

                            #14
                            Originally posted by vijaydiwakar
                            see this is a facility given expolicitly by Microsoft to tress Cancel Button click
                            u may avoid this line but for that ur code must be prepared for handling cancel btn
                            have u placed Commandialog box on ur form?
                            if yes check its name is same as that of commandialogebo x1
                            which u've used in With bolck

                            Hai.
                            Sorry, i can't put the CommonDiaog Box in my form. Because the error occured, when i go to put the CommonDialog Box in my Access Form.

                            I already post the error message

                            You don't have the license required to use this ActiveX control.

                            You tried to open a form containing an OLE object or an ActiveX control or you tried to create an ActiveX control. To obtain the appropriate license, contact the company that provides the licensed OLE object or ActiveX control.



                            Then i try to Register the many Control, like comcat.dll, comctl32.dll, comdlg32.dll, COMDLG32.OCX.

                            The COMDLG32.OCX only was Registered Successfully. But i have the same problem.

                            The error is:



                            c:\windows\syst em32\comctl32.d ll was loaded, but the DllRegisterServ er entry point was not found.

                            This file can not be registered.


                            So, still i am stuck. Pls help me

                            I don't know why this error could be occured. if anybody know, how to solve this error.

                            Please let me know.

                            Comment

                            • iburyak
                              Recognized Expert Top Contributor
                              • Nov 2006
                              • 1016

                              #15
                              Originally posted by ttamilvanan81
                              Hai.
                              Sorry, i can't put the CommonDiaog Box in my form. Because the error occured, when i go to put the CommonDialog Box in my Access Form.

                              I already post the error message

                              You don't have the license required to use this ActiveX control.

                              You tried to open a form containing an OLE object or an ActiveX control or you tried to create an ActiveX control. To obtain the appropriate license, contact the company that provides the licensed OLE object or ActiveX control.



                              Then i try to Register the many Control, like comcat.dll, comctl32.dll, comdlg32.dll, COMDLG32.OCX.

                              The COMDLG32.OCX only was Registered Successfully. But i have the same problem.

                              The error is:



                              c:\windows\syst em32\comctl32.d ll was loaded, but the DllRegisterServ er entry point was not found.

                              This file can not be registered.


                              So, still i am stuck. Pls help me

                              I don't know why this error could be occured. if anybody know, how to solve this error.

                              Please let me know.
                              You should have edit rights on your C: drive.

                              Can you create a text file on your C drive with no problem?

                              If not this is a problem VB needs some rights on your local drive to make it work.

                              Also it is possible that you are using not authentic VB version.

                              Thank you.

                              Comment

                              Working...