Re: running a query in a loop
- From: "Douglas J. Steele" <NOSPAM_djsteele@xxxxxxxxxxxxxxxxx>
- Date: Sun, 8 Jan 2006 09:23:03 -0500
"Steve Schapel" <schapel@xxxxxxxxxxx> wrote in message
news:O7bcc79EGHA.376@xxxxxxxxxxxxxxxxxxxxxxx
> Bob,
>
> As regards your code...
>
>> strSQL = "INSERT INTO tblMissingCommissionReport(LoanNumber, Date) " & _
>> " SELECT tblDate.MonthYear" & _
>> " FROM tblDate" & _
>> " WHERE MonthYear < Now()" & _
>> " AND Format ([MonthYear],"mmmm,yyyy")" & _
>> " Not In ( SELECT Format ([PaymentDate],"mmmm,yyyy")" &_
>> " FROM tblCommission" & _
>> " WHERE LoanNo =" & rst!LoanNo & ")"
>
> ... I can only see one place where it will definitely choke, which is no
> space in one of the &_ bits.
>
> The word 'date' is a Reserved Word (i.e. has a special meaning) in Access,
> and should not be used as the name of a field or control. If you do, it
> should always be enclosed in []s in code. However, if this causes an
> error, I doubt that Access would call it a syntax error.
>
> Also I think there would normally be spaces in the INSERT INTO clause.
>
> The keyword VALUES is not applicable in this case.
>
> You can put a ; at the end if you like, but it is not necessary.
>
> So, try it with these changes...
> strSQL = "INSERT INTO tblMissingCommissionReport ( LoanNumber, [Date] ) "
> & _
> " SELECT tblDate.MonthYear" & _
> " FROM tblDate" & _
> " WHERE MonthYear < Now()" & _
> " AND Format ([MonthYear],"mmmm,yyyy")" & _
> " Not In ( SELECT Format ([PaymentDate],"mmmm,yyyy")" & _
> " FROM tblCommission" & _
> " WHERE LoanNo =" & rst!LoanNo & ")"
The INSERT INTO statement is trying to insert into 2 fields, but only one
value is being provided.
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)
.
- Follow-Ups:
- Re: running a query in a loop
- From: Steve Schapel
- Re: running a query in a loop
- From: Steve Schapel
- Re: running a query in a loop
- References:
- running a query in a loop
- From: Bob
- Re: running a query in a loop
- From: Steve Schapel
- Re: running a query in a loop
- From: Bob
- Re: running a query in a loop
- From: Steve Schapel
- running a query in a loop
- Prev by Date: Re: Writing to a range of cells
- Next by Date: Re: How can I change a Cell of a List View
- Previous by thread: Re: running a query in a loop
- Next by thread: Re: running a query in a loop
- Index(es):
Relevant Pages
|