Compile error: method or data member not found

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,227
Office Version
  1. 2010
Platform
  1. Windows
Hi good afternoon please can you help me please with the below code. Compile error: method or data member not found on Me.Label2.Text, line and Private Sub CommandButton2_Click() is highlighted with a yellow background. Hope you can help me please to why i am getting this error. i have also got a module 3 for this code to work.
VBA Code:
Private Sub CommandButton2_Click()
Const PR_SECURITY_FLAGS = "http://schemas.microsoft.com/mapi/proptag/0x6E010003"
    
    Dim aOutlook As Object
    Dim aEmail As Object
    Dim ulFlags As Integer
    Dim rngeAddresses As Range, rngeCell As Range, strRecipients As String
    
    Set aOutlook = CreateObject("Outlook.Application")
    Set aEmail = aOutlook.CreateItem(0)

    ulFlags = ulFlags Or &H1 ' SECFLAG_ENCRYPTED
    
    aEmail.PropertyAccessor.SetProperty PR_SECURITY_FLAGS, (ulFlags)

          aEmail.HTMLBody = "<html><body>" & _
                            "<p>Hi " & Me.TextBox13.Value & "</p>" & _
                            "<table border=""1"", cellpadding=""10"", style=background:""#a6bbde"" >" & _
                "<tr>" & _
                            "<td>" & Me.Label2.Text & "</td><td>" & Me.TextBox1.Text & "</td>" & _
                            "<td>" & Me.Label3.Text & "</td><td>" & Me.TextBox2.Text & "</td>" & _
                            "<td>" & Me.Label1.Text & "</td><td>" & Me.TextBox10.Text & "</td>" & _
                            "</tr>" & _
                "<tr>" & _
                            "<th>Address:</th>" & _
                            "<td>" & Me.Labell.Value & "</td><td>" & Me.TextBox6.Value & "</td>" & _
                            "<td>" & Me.Label2.Value & "</td><td>" & Me.TextBox7.Value & "</td>" & _
                            "<td>" & Me.Label3.Value & "</td><td>" & Me.TextBox8.Value & "</td>" & _
                            "<td>" & Me.Label14.Value & "</td><td>" & Me.TextBox8.Value & "</td>" & _
                            "</tr>" & _
                            "<th>Job:</th>" & _
                            "<td>" & Me.Label6.Value & "</td><td>" & Me.TextBox8.Value & "</td>" & _
                            "<td>" & Me.Label7.Value & "</td><td>" & Me.TextBox8.Value & "</td>" & _
                            "</table>" & _
                "<br><br><br><br><br><br>" & _
                "<p>Many Thanks</p>" & _
                "<p>Complex Team</p>" & _
                "</body></html>"


        aEmail.Recipients.Add (UserForm6.TextBox13.Value)
        aEmail.CC = ""
        aEmail.BCC = ""
        aEmail.Subject = "Daily " & (UserForm6.ComboBox2.Value)
        aEmail.Display

Unload Me

End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
The Label control doesn't have a Text property - you want Caption
 
Upvote 0
The Label control doesn't have a Text property - you want Caption
Hi thank you for replying back, i have changed all the labels now to label1.caption for example but i am now getting a 'Run-time error 404, There must be at least one name or contact group in the To, Cc, or Bcc box' hope you can still help me please?
Code:
aEmail.Recipients.Add (UserForm6.TextBox13.Value)
VBA Code:
Private Sub CommandButton2_Click()
Const PR_SECURITY_FLAGS = "http://schemas.microsoft.com/mapi/proptag/0x6E010003"
   
    Dim aOutlook As Object
    Dim aEmail As Object
    Dim ulFlags As Integer
    Dim rngeAddresses As Range, rngeCell As Range, strRecipients As String
   
    Set aOutlook = CreateObject("Outlook.Application")
    Set aEmail = aOutlook.CreateItem(0)

    ulFlags = ulFlags Or &H1 ' SECFLAG_ENCRYPTED
   
    aEmail.PropertyAccessor.SetProperty PR_SECURITY_FLAGS, (ulFlags)

          aEmail.HTMLBody = "<html><body>" & _
                            "<p>Hi " & Me.TextBox13.Value & "</p>" & _
                            "<table border=""1"", cellpadding=""10"", style=background:""#a6bbde"" >" & _
                "<tr>" & _
                            "<td>" & Me.Label12.Caption & "</td><td>" & Me.TextBox1.Text & "</td>" & _
                            "<td>" & Me.Label13.Caption & "</td><td>" & Me.TextBox2.Text & "</td>" & _
                            "<td>" & Me.Label14.Caption & "</td><td>" & Me.TextBox10.Text & "</td>" & _
                            "</tr>" & _
                "<tr>" & _
                            "<th>Address:</th>" & _
                            "<td>" & Me.Label1.Caption & "</td><td>" & Me.TextBox6.Value & "</td>" & _
                            "<td>" & Me.Label2.Caption & "</td><td>" & Me.TextBox7.Value & "</td>" & _
                            "<td>" & Me.Label3.Caption & "</td><td>" & Me.TextBox8.Value & "</td>" & _
                            "<td>" & Me.Label4.Caption & "</td><td>" & Me.TextBox8.Value & "</td>" & _
                            "</tr>" & _
                            "<th>Job:</th>" & _
                            "<td>" & Me.Label6.Caption & "</td><td>" & Me.TextBox8.Value & "</td>" & _
                            "<td>" & Me.Label7.Caption & "</td><td>" & Me.TextBox8.Value & "</td>" & _
                            "</table>" & _
                "<br><br><br><br><br><br>" & _
                "<p>Many Thanks</p>" & _
                "<p>Complex Team</p>" & _
                "</body></html>"


        aEmail.Recipients.Add (UserForm6.TextBox13.Value)
        aEmail.CC = ""
        aEmail.BCC = ""
        aEmail.Subject = "Daily " & (UserForm6.ComboBox2.Value)
        aEmail.Display

Unload Me

End Sub
 
Upvote 0
What is in Textbox13?
 
Upvote 0
Are you sure Userform6 is still loaded and definitely has something in that textbox? That being blank is the only way I can see you could get that error.
 
Upvote 0
Solution
Are you sure Userform6 is still loaded and definitely has something in that textbox? That being blank is the only way I can see you could get that error.
silly me that has sorted it thank you i didnt realise it was blank thank you
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top