PC Review


Reply
Thread Tools Rate Thread

Compile Error: For without next

 
 
=?Utf-8?B?aGVsZWd1YQ==?=
Guest
Posts: n/a
 
      23rd May 2004
new to VB the code below keeps returning Compile error need help Pleas

Private Sub cmdCreateList_Click(

Dim Item As Varian
Dim intCounter As Intege
Dim intMaxCount As Intege
Dim strSQL As Strin
Dim frm As For
Dim ctl As Contro
Dim varItm As Varian
Dim strGroup As Strin
Dim strTable As Strin

Application.SetOption "Confirm Action Queries", Fals
'Cleans out the data from the Mailing List tabl
DoCmd.RunSQL "DELETE tblMailingList.* FROM tblMailingList

'Set up counter to select all list
intMaxCount = Me.MailingList.ListCount -
intCounter =


'Goes through list box and gets selected group
Set ctl = Me.MailingLis
For Each varItm In ctl.ItemsSelecte
strGroup = ctl.Column(0, varItm

'Inserts records for each selected group into tblMailingLis
strSQL = "INSERT INTO tblMailingList ( Salutation, FirstName, MiddleName, LastName, Suffix, " &
"Address, City, State, Zip, Company ) " &
"SELECT MainDonorBio.Prefix, MainDonorBio.FirstName, MainDonorBio.MI, MainDonorBio.LastName, " &
"MainDonorBio.Suffix, IIf([PreferredMailingAddress]='P',[HomeAddressLineOne],[HomeAddressLineTwo],[WorkAddressLineOne],[WorkAddressLineTwo]) AS Address, " &
"IIf([PreferredMailingAddress]='P',[HomeCity],[WorkCity]) AS City, " &
"IIf([PreferredMailingAddress]='P',[HomeStateOrProvince],[WorkStateOrProvince]) AS State, " &
"IIf([PreferredMailingAddress]='P',[HomePostalCode],[WorkPostalCode]) AS Zip, " &
"IIf([PreferredMailingAddress]='P',Null,[Organization]) AS Company1 " &
"FROM MainDonorBio INNER JOIN Mailings ON MainDonorBio.DonorID = Mailings.DonorID " &
"WHERE (((Mailings.MailingList)= '" & strGroup & "') AND (MainDonorBio.BadMailingAddressYN)=False)

DoCmd.RunSQL (strSQL


'Cleans out the data from tblMailingListUnique
DoCmd.RunSQL "DELETE tblMailingListUnique.* FROM tblMailingListUnique

'Appends records from tblMailingList to tblMailingListUnique so tha
'duplicates are removed
DoCmd.OpenQuery "qryMailingListAppend
DoCmd.OpenTable "tblMailingListUnique

End Sub
 
Reply With Quote
 
 
 
 
Cheryl Fischer
Guest
Posts: n/a
 
      23rd May 2004
You are missing a Next statement, which For...Next loops require. You need
to insert: Next varItm somewhere in your code so that Access knows when
to proceed/loop to the next selected item. I suspect the Next varItm
needs to be inserted after your "DoCmd.RunSQL (strSQL)" statement.


--

Cheryl Fischer, MVP Microsoft Access



"helegua" <(E-Mail Removed)> wrote in message
news:8C318DAB-3FBF-48D6-9FBD-(E-Mail Removed)...
> new to VB the code below keeps returning Compile error need help Please
>
> Private Sub cmdCreateList_Click()
>
> Dim Item As Variant
> Dim intCounter As Integer
> Dim intMaxCount As Integer
> Dim strSQL As String
> Dim frm As Form
> Dim ctl As Control
> Dim varItm As Variant
> Dim strGroup As String
> Dim strTable As String
>
> Application.SetOption "Confirm Action Queries", False
> 'Cleans out the data from the Mailing List table
> DoCmd.RunSQL "DELETE tblMailingList.* FROM tblMailingList"
>
> 'Set up counter to select all lists
> intMaxCount = Me.MailingList.ListCount - 1
> intCounter = 0
>
>
> 'Goes through list box and gets selected groups
> Set ctl = Me.MailingList
> For Each varItm In ctl.ItemsSelected
> strGroup = ctl.Column(0, varItm)
>
> 'Inserts records for each selected group into tblMailingList
> strSQL = "INSERT INTO tblMailingList ( Salutation, FirstName, MiddleName,

LastName, Suffix, " & _
> "Address, City, State, Zip, Company ) " & _
> "SELECT MainDonorBio.Prefix, MainDonorBio.FirstName, MainDonorBio.MI,

MainDonorBio.LastName, " & _
> "MainDonorBio.Suffix,

IIf([PreferredMailingAddress]='P',[HomeAddressLineOne],[HomeAddressLineTwo],
[WorkAddressLineOne],[WorkAddressLineTwo]) AS Address, " & _
> "IIf([PreferredMailingAddress]='P',[HomeCity],[WorkCity]) AS City, " & _
>

"IIf([PreferredMailingAddress]='P',[HomeStateOrProvince],[WorkStateOrProvinc
e]) AS State, " & _
> "IIf([PreferredMailingAddress]='P',[HomePostalCode],[WorkPostalCode]) AS

Zip, " & _
> "IIf([PreferredMailingAddress]='P',Null,[Organization]) AS Company1 " & _
> "FROM MainDonorBio INNER JOIN Mailings ON MainDonorBio.DonorID =

Mailings.DonorID " & _
> "WHERE (((Mailings.MailingList)= '" & strGroup & "') AND

(MainDonorBio.BadMailingAddressYN)=False)"
>
> DoCmd.RunSQL (strSQL)
>
>
> 'Cleans out the data from tblMailingListUnique.
> DoCmd.RunSQL "DELETE tblMailingListUnique.* FROM

tblMailingListUnique"
>
> 'Appends records from tblMailingList to tblMailingListUnique so that
> 'duplicates are removed.
> DoCmd.OpenQuery "qryMailingListAppend"
> DoCmd.OpenTable "tblMailingListUnique"
>
> End Sub



 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      23rd May 2004
The message is pretty explicit.

You have a statement "For Each varItm In ctl.ItemsSelected" in your code,
but you don't have a "Next" (or "Next varItm") statement anywhere.

I'm guessing it needs to be between

DoCmd.RunSQL (strSQL)

and

'Cleans out the data from tblMailingListUnique.
DoCmd.RunSQL "DELETE tblMailingListUnique.* FROM tblMailingListUnique"


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"helegua" <(E-Mail Removed)> wrote in message
news:8C318DAB-3FBF-48D6-9FBD-(E-Mail Removed)...
> new to VB the code below keeps returning Compile error need help Please
>
> Private Sub cmdCreateList_Click()
>
> Dim Item As Variant
> Dim intCounter As Integer
> Dim intMaxCount As Integer
> Dim strSQL As String
> Dim frm As Form
> Dim ctl As Control
> Dim varItm As Variant
> Dim strGroup As String
> Dim strTable As String
>
> Application.SetOption "Confirm Action Queries", False
> 'Cleans out the data from the Mailing List table
> DoCmd.RunSQL "DELETE tblMailingList.* FROM tblMailingList"
>
> 'Set up counter to select all lists
> intMaxCount = Me.MailingList.ListCount - 1
> intCounter = 0
>
>
> 'Goes through list box and gets selected groups
> Set ctl = Me.MailingList
> For Each varItm In ctl.ItemsSelected
> strGroup = ctl.Column(0, varItm)
>
> 'Inserts records for each selected group into tblMailingList
> strSQL = "INSERT INTO tblMailingList ( Salutation, FirstName, MiddleName,

LastName, Suffix, " & _
> "Address, City, State, Zip, Company ) " & _
> "SELECT MainDonorBio.Prefix, MainDonorBio.FirstName, MainDonorBio.MI,

MainDonorBio.LastName, " & _
> "MainDonorBio.Suffix,

IIf([PreferredMailingAddress]='P',[HomeAddressLineOne],[HomeAddressLineTwo],
[WorkAddressLineOne],[WorkAddressLineTwo]) AS Address, " & _
> "IIf([PreferredMailingAddress]='P',[HomeCity],[WorkCity]) AS City, " & _
>

"IIf([PreferredMailingAddress]='P',[HomeStateOrProvince],[WorkStateOrProvinc
e]) AS State, " & _
> "IIf([PreferredMailingAddress]='P',[HomePostalCode],[WorkPostalCode]) AS

Zip, " & _
> "IIf([PreferredMailingAddress]='P',Null,[Organization]) AS Company1 " & _
> "FROM MainDonorBio INNER JOIN Mailings ON MainDonorBio.DonorID =

Mailings.DonorID " & _
> "WHERE (((Mailings.MailingList)= '" & strGroup & "') AND

(MainDonorBio.BadMailingAddressYN)=False)"
>
> DoCmd.RunSQL (strSQL)
>
>
> 'Cleans out the data from tblMailingListUnique.
> DoCmd.RunSQL "DELETE tblMailingListUnique.* FROM

tblMailingListUnique"
>
> 'Appends records from tblMailingList to tblMailingListUnique so that
> 'duplicates are removed.
> DoCmd.OpenQuery "qryMailingListAppend"
> DoCmd.OpenTable "tblMailingListUnique"
>
> End Sub



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Export report to Excel, Error message "Compile Error: Argument not mc Microsoft Access External Data 0 16th Jul 2009 10:11 PM
VBAProject name compile error, not defined at compile time Matthew Dodds Microsoft Excel Programming 1 13th Dec 2005 08:17 PM
Compile error. in table-level validation expression. (Error 3320) =?Utf-8?B?RG9ubmE=?= Microsoft Access Forms 4 21st Mar 2005 09:13 PM
error message in Winword. ( Compile error in hidden module: AutoE. =?Utf-8?B?TXkgRXJyb3IgUHJvYmxlbQ==?= Microsoft Access Getting Started 1 4th Oct 2004 03:52 AM
excel 2003 error>> compile error in hidden module: ThisWorkbook clayton Microsoft Excel Misc 4 22nd Jun 2004 03:02 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:14 PM.