Results 1 to 7 of 7
  1. #1
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,329

    Invalid Next Control Variable Reference

    Hi Guy's, I should be able to achieve this one easily using examples and adapting what I already have.

    I am trying to output 3 list box contents to 1 x email body.

    Its returning Invalid Next Control Variable Reference Next intListA ?

    Also, I can't seem to get the contents of all 3 lists to the email body.

    Have I got the sequence/procedure correct ???

    Code:
    Dim subject As String, Body As String, a As String, b As String, c As String, lne As String, wkr As String, UserName As StringDim OutApp As Outlook.Application, OutAccount As Outlook.Account
    Dim OutMail As Outlook.MailItem
    Dim intListB As Integer, intListC As Integer, intListA As Integer
    Dim eDisc As String, eDisc2 As String, SigFile As String, myMonth As String
    
    
    myMonth = Format(Now(), "mm")
    If myMonth <> "12" Then
    SigFile = "DMT dave@ Email Signature.jpg"
    Else
    SigFile = "DMT Xmas Signature.jpg"
    End If
    
    
    eDisc = "COMPANY REMOVED is a limited company registered in England and Wales, Registered number: REG REMOVED." & vbNewLine & _
    "Registered office: ADDRESS REMOVED"
    eDisc2 = "This message and any associated files is intended only for the use of the named recipient(s) and may contain information which is confidential, subject to copy write or constitutes a trade secret." & vbNewLine & _
    "If you are not the name recipient(s) you are hereby notified that any copying or distribution of this message, or files associated with this message, is strictly prohibited." & vbNewLine & _
    "If you have received this message in error, please notify us immediately by replying to this email and deleting from your computer." & vbNewLine & _
    "Any files attached to this email will have been checked with anti virus detection software prior to sending, but you should carry out your own virus check before opening any attachment." & vbNewLine & _
    "COMPANY REMOVED do not accept liability for any loss or damage which may be caused by software viruses."
    
    
    lne = ".........................................................................................................."
    wkr = "With Kind Regards"
    UserName = Forms!frmMainMenu!txtLogin
    
    
      On Error Resume Next
      Set OutApp = GetObject(, "Outlook.Application")
      If OutApp Is Nothing Then
        Set OutApp = CreateObject("Outlook.Application")
      End If
      On Error GoTo 0
    
    
    
    
    
    
            For intListA = 0 To Me.lstAdded.ListCount - 1
            For intListB = 0 To Me.lstDeliveries.ListCount - 1
            For intListC = 0 To Me.lstCollections.ListCount - 1
         
        a = Me.lstAdded.Column(0) & ", " & Me.lstAdded.Column(1) & ", " & Me.lstAdded.Column(2) & ", " & Me.lstAdded.Column(3) & ", " & Me.lstAdded.Column(4) _
            & ", " & Me.lstAdded.Column(5) & ", " & Me.lstAdded.Column(6) & ", " & Me.lstAdded.Column(7) & ", " & Me.lstAdded.Column(8) & "|"
            
        b = Me.lstDeliveries.Column(0) & ", " & Me.lstDeliveries.Column(1) & ", " & Me.lstDeliveries.Column(2) & ", " & Me.lstDeliveries.Column(3) & ", " & Me.lstDeliveries.Column(4) _
            & ", " & Me.lstDeliveries.Column(5) & ", " & Me.lstDeliveries.Column(6) & ", " & Me.lstDeliveries.Column(7) & ", " & Me.lstDeliveries.Column(8) & "|"
        
        c = Me.lstCollections.Column(0) & ", " & Me.lstCollections.Column(1) & ", " & Me.lstCollections.Column(2) & ", " & Me.lstCollections.Column(3) & ", " & Me.lstCollections.Column(4) _
            & ", " & Me.lstCollections.Column(5) & ", " & Me.lstCollections.Column(6) & ", " & Me.lstCollections.Column(7) & ", " & Me.lstCollections.Column(8) & "|"
        
        
             Me.lstAdded.Selected(intListA) = True
             Me.lstDeliveries.Selected(intListB) = True
             Me.lstCollections.Selected(intListC) = True
             
             
             Set OutMail = OutApp.CreateItem(olMailItem)
            Set OutAccount = OutMail.Session.Accounts.Item(1)
            With OutMail
            .To = Me.cboEmailTo.Column(3)
             .subject = SubStart & Forms!frmSearch!txtFind & " " & "DMT Results Found"
            .HTMLBody = lne & "<br>" & "ITEMS ADDED TO THE SYSTEM" & "<br> " & _
            Replace(a, "|", "<br>") & "<br>" & lne & _
            "ITEMS IN DELIVERIES " & _
            Replace(b, "|", "<br>") & "<br>" & lne & _
            "ITEMS IN COLLECTIONS " & _
            Replace(c, "|", "<br>") & "<br>" & lne & _
            wkr & "<br>" & "<br>" & _
            UserName & "<br>" & "<br>" & _
            "<P><IMG border=0 hspace=0 alt='' src='file://T:/DMT Ltd/Logo Media/" & SigFile & "' align=baseline></P>" & "<br>" & "<br>" & _
            "<FONT color=#00008B>" & eDisc & "<br>" & "<FONT color =#00008B>" & eDisc2
            .SendUsingAccount = OutAccount
            .Display
             End With
             
        Next intListA
        Next intListB
        Next intListC
      
    Set OutMail = Nothing
    Set OutApp = Nothing


  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    The Next lines are in wrong order. It is not necessary to reference the variable on Next line. Just use Next.

    But I am not sure why you have nested loops.

    Are these multi-select listboxes? If you want to build 3 strings for multiple selections in each combobox, this code will not do that.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,329
    Hi June7, thank you, i have removed all FORS and all NEXTS so i don't have any at all

    Yes i am trying add to mail body all 3 list contents, after removing FORS and NEXTS, the email body will show excluding list contents, i guess i just need to find out how add these from strings A,B and C ?

    Email result without FORS and NEXTS

    .................................................. .................................................. ......
    ITEMS ADDED TO THE SYSTEM
    , , , , , , , ,

    .................................................. .................................................. ......ITEMS IN DELIVERIES , , , , , , , ,

    .................................................. .................................................. ......ITEMS IN COLLECTIONS , , , , , , , ,

    .................................................. .................................................. ......With Kind Regards

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    Didn't answer question. Are these multi-select listboxes?

    Do users make multiple selections in listboxes and you want to build strings of multiple selections?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,329
    Hi June7, sorry yes they are, i think im not selecting the data?

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    I don't understand. Why have multi-select listboxes if users are not selecting from them?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,275
    Quote Originally Posted by DMT Dave View Post
    Hi Guy's, I should be able to achieve this one easily using examples and adapting what I already have.

    I am trying to output 3 list box contents to 1 x email body.

    Its returning Invalid Next Control Variable Reference Next intListA ?

    Also, I can't seem to get the contents of all 3 lists to the email body.

    Have I got the sequence/procedure correct ???

    Code:
    Dim subject As String, Body As String, a As String, b As String, c As String, lne As String, wkr As String, UserName As StringDim OutApp As Outlook.Application, OutAccount As Outlook.Account
    Dim OutMail As Outlook.MailItem
    Dim intListB As Integer, intListC As Integer, intListA As Integer
    Dim eDisc As String, eDisc2 As String, SigFile As String, myMonth As String
    
    
    myMonth = Format(Now(), "mm")
    If myMonth <> "12" Then
    SigFile = "DMT dave@ Email Signature.jpg"
    Else
    SigFile = "DMT Xmas Signature.jpg"
    End If
    
    
    eDisc = "COMPANY REMOVED is a limited company registered in England and Wales, Registered number: REG REMOVED." & vbNewLine & _
    "Registered office: ADDRESS REMOVED"
    eDisc2 = "This message and any associated files is intended only for the use of the named recipient(s) and may contain information which is confidential, subject to copy write or constitutes a trade secret." & vbNewLine & _
    "If you are not the name recipient(s) you are hereby notified that any copying or distribution of this message, or files associated with this message, is strictly prohibited." & vbNewLine & _
    "If you have received this message in error, please notify us immediately by replying to this email and deleting from your computer." & vbNewLine & _
    "Any files attached to this email will have been checked with anti virus detection software prior to sending, but you should carry out your own virus check before opening any attachment." & vbNewLine & _
    "COMPANY REMOVED do not accept liability for any loss or damage which may be caused by software viruses."
    
    
    lne = ".........................................................................................................."
    wkr = "With Kind Regards"
    UserName = Forms!frmMainMenu!txtLogin
    
    
      On Error Resume Next
      Set OutApp = GetObject(, "Outlook.Application")
      If OutApp Is Nothing Then
        Set OutApp = CreateObject("Outlook.Application")
      End If
      On Error GoTo 0
    
    
    
    
    
    
            For intListA = 0 To Me.lstAdded.ListCount - 1
            For intListB = 0 To Me.lstDeliveries.ListCount - 1
            For intListC = 0 To Me.lstCollections.ListCount - 1
         
        a = Me.lstAdded.Column(0) & ", " & Me.lstAdded.Column(1) & ", " & Me.lstAdded.Column(2) & ", " & Me.lstAdded.Column(3) & ", " & Me.lstAdded.Column(4) _
            & ", " & Me.lstAdded.Column(5) & ", " & Me.lstAdded.Column(6) & ", " & Me.lstAdded.Column(7) & ", " & Me.lstAdded.Column(8) & "|"
            
        b = Me.lstDeliveries.Column(0) & ", " & Me.lstDeliveries.Column(1) & ", " & Me.lstDeliveries.Column(2) & ", " & Me.lstDeliveries.Column(3) & ", " & Me.lstDeliveries.Column(4) _
            & ", " & Me.lstDeliveries.Column(5) & ", " & Me.lstDeliveries.Column(6) & ", " & Me.lstDeliveries.Column(7) & ", " & Me.lstDeliveries.Column(8) & "|"
        
        c = Me.lstCollections.Column(0) & ", " & Me.lstCollections.Column(1) & ", " & Me.lstCollections.Column(2) & ", " & Me.lstCollections.Column(3) & ", " & Me.lstCollections.Column(4) _
            & ", " & Me.lstCollections.Column(5) & ", " & Me.lstCollections.Column(6) & ", " & Me.lstCollections.Column(7) & ", " & Me.lstCollections.Column(8) & "|"
        
        
             Me.lstAdded.Selected(intListA) = True
             Me.lstDeliveries.Selected(intListB) = True
             Me.lstCollections.Selected(intListC) = True
             
             
             Set OutMail = OutApp.CreateItem(olMailItem)
            Set OutAccount = OutMail.Session.Accounts.Item(1)
            With OutMail
            .To = Me.cboEmailTo.Column(3)
             .subject = SubStart & Forms!frmSearch!txtFind & " " & "DMT Results Found"
            .HTMLBody = lne & "<br>" & "ITEMS ADDED TO THE SYSTEM" & "<br> " & _
            Replace(a, "|", "<br>") & "<br>" & lne & _
            "ITEMS IN DELIVERIES " & _
            Replace(b, "|", "<br>") & "<br>" & lne & _
            "ITEMS IN COLLECTIONS " & _
            Replace(c, "|", "<br>") & "<br>" & lne & _
            wkr & "<br>" & "<br>" & _
            UserName & "<br>" & "<br>" & _
            "<P><IMG border=0 hspace=0 alt='' src='file://T:/DMT Ltd/Logo Media/" & SigFile & "' align=baseline></P>" & "<br>" & "<br>" & _
            "<FONT color=#00008B>" & eDisc & "<br>" & "<FONT color =#00008B>" & eDisc2
            .SendUsingAccount = OutAccount
            .Display
             End With
             
        Next intListA
        Next intListB
        Next intListC
      
    Set OutMail = Nothing
    Set OutApp = Nothing
    Indentation,Indentation,Indentation
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Invalid reference to the parent property
    By Access_Novice in forum Programming
    Replies: 1
    Last Post: 12-28-2013, 05:17 PM
  2. Invalid or Unqualified Reference
    By swavemeisterg in forum Forms
    Replies: 4
    Last Post: 04-17-2013, 02:03 PM
  3. Invalid or unqualified reference
    By mitchmcc in forum Access
    Replies: 3
    Last Post: 12-26-2011, 08:53 AM
  4. Invalid database object reference.
    By jgelpi16 in forum Programming
    Replies: 4
    Last Post: 04-11-2011, 02:48 PM
  5. Variable within form control reference
    By Tyork in forum Programming
    Replies: 2
    Last Post: 10-13-2010, 09:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums