473,763 Members | 7,611 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

missing records from coded recordset when compared to qbe

Jan
Hi

I have a database that I use to keep track of the sales promotions that we
send to companies.

I normally send a mailing based on a subset of the companies in the database
(found using the query: QryICTMassDistr ibution3) , I then use a form and
the code below to create a new record in the corrispondence table to show
what corrispondence has been sent to various companies.

However, when I tried this for our latest mailing it only worked for 52 of
348 the records.
The QryICTMassDistr ibution3 query, links several tables, and returns 348
records when run normally but in the code below the recordset only seems to
have 52 records.

Can anyone suggest where I have gone wrong?

Many thanks
JM

the code:

Private Sub Command0_Click( )

Dim cnxn As ADODB.Connectio n
Dim rs As ADODB.Recordset
Set cnxn = CurrentProject. Connection
Set rs = New ADODB.Recordset
Set linktable = New ADODB.Recordset
Dim count As Integer
rs.Open "Select Count(*) As MatchCount FROM QryICTMassDistr ibution3", cnxn
linktable.Open "TblCompanyId_C orrespondence", cnxn, adOpenKeyset,
adLockOptimisti c
rs.MoveFirst
MsgBox "you are about to process " & rs!MatchCount & " records"
count = 0
While Not rs.EOF
count = count + 1
linktable.AddNe w
linktable.Field s("CompanyId" ) = rs.Fields("Comp anyId")
linktable.Field s("Corespondenc eId") = Text5.Value
rs.MoveNext
Wend
rs.Close
MsgBox count & " records added to corrispondence table"

Set rs = Nothing
linktable.Updat e
linktable.Close
Rem Set linktable = Nothing
End Sub

Nov 13 '05 #1
13 3479
To be honest, I can't see how it does anything at all.

The rs.open will return a recordset with a single record containing a count
value. Looping through that recordset will therefore loop just once.
The .addnew needs a corresponding .update in order to tell the linktable
recordset to actually retain the record you've added.

Have you tried dropping a breakpoint in there and following your logic
through?

Why not just use an append query? It'd be a great deal easier.
"Jan" <Ja************ *@hotmail.com> wrote in message
news:d3******** **@news8.svr.po l.co.uk...
Hi

I have a database that I use to keep track of the sales promotions that we
send to companies.

I normally send a mailing based on a subset of the companies in the database (found using the query: QryICTMassDistr ibution3) , I then use a form and
the code below to create a new record in the corrispondence table to show
what corrispondence has been sent to various companies.

However, when I tried this for our latest mailing it only worked for 52 of
348 the records.
The QryICTMassDistr ibution3 query, links several tables, and returns 348
records when run normally but in the code below the recordset only seems to have 52 records.

Can anyone suggest where I have gone wrong?

Many thanks
JM

the code:

Private Sub Command0_Click( )

Dim cnxn As ADODB.Connectio n
Dim rs As ADODB.Recordset
Set cnxn = CurrentProject. Connection
Set rs = New ADODB.Recordset
Set linktable = New ADODB.Recordset
Dim count As Integer
rs.Open "Select Count(*) As MatchCount FROM QryICTMassDistr ibution3", cnxn
linktable.Open "TblCompanyId_C orrespondence", cnxn, adOpenKeyset,
adLockOptimisti c
rs.MoveFirst
MsgBox "you are about to process " & rs!MatchCount & " records"
count = 0
While Not rs.EOF
count = count + 1
linktable.AddNe w
linktable.Field s("CompanyId" ) = rs.Fields("Comp anyId")
linktable.Field s("Corespondenc eId") = Text5.Value
rs.MoveNext
Wend
rs.Close
MsgBox count & " records added to corrispondence table"

Set rs = Nothing
linktable.Updat e
linktable.Close
Rem Set linktable = Nothing
End Sub

Nov 13 '05 #2
"Rob Oldfield" <bl**@blah.co m> wrote in message
news:O8******** ******@TK2MSFTN GP10.phx.gbl...
To be honest, I can't see how it does anything at all.

The rs.open will return a recordset with a single record containing a count value. Looping through that recordset will therefore loop just once.
The .addnew needs a corresponding .update in order to tell the linktable
recordset to actually retain the record you've added.

Have you tried dropping a breakpoint in there and following your logic
through?

Why not just use an append query? It'd be a great deal easier.
You know, I'm glad you posted that. I looked at the OP's code earlier and
it just didn't make any sense. I thought it must be some technique that I
didn't comprehend. What I couldn't figure out is how she got 52 records out
of that code.

"Jan" <Ja************ *@hotmail.com> wrote in message
news:d3******** **@news8.svr.po l.co.uk...
Hi

I have a database that I use to keep track of the sales promotions that we send to companies.

I normally send a mailing based on a subset of the companies in the

database
(found using the query: QryICTMassDistr ibution3) , I then use a form and the code below to create a new record in the corrispondence table to show what corrispondence has been sent to various companies.

However, when I tried this for our latest mailing it only worked for 52 of 348 the records.
The QryICTMassDistr ibution3 query, links several tables, and returns 348 records when run normally but in the code below the recordset only seems

to
have 52 records.

Can anyone suggest where I have gone wrong?

Many thanks
JM

the code:

Private Sub Command0_Click( )

Dim cnxn As ADODB.Connectio n
Dim rs As ADODB.Recordset
Set cnxn = CurrentProject. Connection
Set rs = New ADODB.Recordset
Set linktable = New ADODB.Recordset
Dim count As Integer
rs.Open "Select Count(*) As MatchCount FROM QryICTMassDistr ibution3", cnxn linktable.Open "TblCompanyId_C orrespondence", cnxn, adOpenKeyset,
adLockOptimisti c
rs.MoveFirst
MsgBox "you are about to process " & rs!MatchCount & " records"
count = 0
While Not rs.EOF
count = count + 1
linktable.AddNe w
linktable.Field s("CompanyId" ) = rs.Fields("Comp anyId")
linktable.Field s("Corespondenc eId") = Text5.Value
rs.MoveNext
Wend
rs.Close
MsgBox count & " records added to corrispondence table"

Set rs = Nothing
linktable.Updat e
linktable.Close
Rem Set linktable = Nothing
End Sub


Nov 13 '05 #3
Jan
Hi

Thanks for the previous comments.

As you may guess programming in VBA isn't my strong point!

I'm not sure I understand why you are saying rs.open only returns one
record? I have actually used this code in the past with different queries
that return 50 to 60 records and it has worked.

How do I make it return all the records?

I cant use an append query as the relationships are too complex and the
query ends up saying 'record set is not updateable'. Hence I decided the
easiest way would be to simple loop through the records in the query and add
their ID together with a correspondence to a new table.

I have got a .update at the end of the code, are you saying it should be in
the loop with the .addnew?

Many thanks for the help
JM

"Rob Oldfield" <bl**@blah.co m> wrote in message
news:O8******** ******@TK2MSFTN GP10.phx.gbl...
To be honest, I can't see how it does anything at all.

The rs.open will return a recordset with a single record containing a
count
value. Looping through that recordset will therefore loop just once.
The .addnew needs a corresponding .update in order to tell the linktable
recordset to actually retain the record you've added.

Have you tried dropping a breakpoint in there and following your logic
through?

Why not just use an append query? It'd be a great deal easier.
"Jan" <Ja************ *@hotmail.com> wrote in message
news:d3******** **@news8.svr.po l.co.uk...
Hi

I have a database that I use to keep track of the sales promotions that
we
send to companies.

I normally send a mailing based on a subset of the companies in the

database
(found using the query: QryICTMassDistr ibution3) , I then use a form and
the code below to create a new record in the corrispondence table to show
what corrispondence has been sent to various companies.

However, when I tried this for our latest mailing it only worked for 52
of
348 the records.
The QryICTMassDistr ibution3 query, links several tables, and returns 348
records when run normally but in the code below the recordset only seems

to
have 52 records.

Can anyone suggest where I have gone wrong?

Many thanks
JM

the code:

Private Sub Command0_Click( )

Dim cnxn As ADODB.Connectio n
Dim rs As ADODB.Recordset
Set cnxn = CurrentProject. Connection
Set rs = New ADODB.Recordset
Set linktable = New ADODB.Recordset
Dim count As Integer
rs.Open "Select Count(*) As MatchCount FROM QryICTMassDistr ibution3",
cnxn
linktable.Open "TblCompanyId_C orrespondence", cnxn, adOpenKeyset,
adLockOptimisti c
rs.MoveFirst
MsgBox "you are about to process " & rs!MatchCount & " records"
count = 0
While Not rs.EOF
count = count + 1
linktable.AddNe w
linktable.Field s("CompanyId" ) = rs.Fields("Comp anyId")
linktable.Field s("Corespondenc eId") = Text5.Value
rs.MoveNext
Wend
rs.Close
MsgBox count & " records added to corrispondence table"

Set rs = Nothing
linktable.Updat e
linktable.Close
Rem Set linktable = Nothing
End Sub


Nov 13 '05 #4
(apologies for accidentally mailing this to your reply address)

I'm afraid that whatever code you have that is working, it's fundamentally
different from this code.

If you take the SQL statement Select Count(*) As MatchCount FROM
QryICTMassDistr ibution3 and paste it into the SQL window of a query, and
then switch to the datasheet, then you'll get a single record, single field
display showing you how many records you have.

You'd be better off just replacing that with Select * FROM
QryICTMassDistr ibution3... that will then give you a loop that works.
You'll be able to use rs.recordcount to return the number of records
returned for your message.

On the .update question then yes, you should have it run inside the loop as
you suggest.

And regarding the idea to use an append query, you should be appending on to
a table - ensuring that the values you're writing into foreign key fields
are correct. That would get around the recordset not being updatable.

"Jan" <Ja************ *@hotmail.com> wrote in message
news:d3******** **@newsg2.svr.p ol.co.uk...
Hi

Thanks for the previous comments.

As you may guess programming in VBA isn't my strong point!

I'm not sure I understand why you are saying rs.open only returns one
record? I have actually used this code in the past with different queries
that return 50 to 60 records and it has worked.

How do I make it return all the records?

I cant use an append query as the relationships are too complex and the
query ends up saying 'record set is not updateable'. Hence I decided the
easiest way would be to simple loop through the records in the query and add their ID together with a correspondence to a new table.

I have got a .update at the end of the code, are you saying it should be in the loop with the .addnew?

Many thanks for the help
JM

"Rob Oldfield" <bl**@blah.co m> wrote in message
news:O8******** ******@TK2MSFTN GP10.phx.gbl...
To be honest, I can't see how it does anything at all.

The rs.open will return a recordset with a single record containing a
count
value. Looping through that recordset will therefore loop just once.
The .addnew needs a corresponding .update in order to tell the linktable
recordset to actually retain the record you've added.

Have you tried dropping a breakpoint in there and following your logic
through?

Why not just use an append query? It'd be a great deal easier.
"Jan" <Ja************ *@hotmail.com> wrote in message
news:d3******** **@news8.svr.po l.co.uk...
Hi

I have a database that I use to keep track of the sales promotions that
we
send to companies.

I normally send a mailing based on a subset of the companies in the

database
(found using the query: QryICTMassDistr ibution3) , I then use a form and the code below to create a new record in the corrispondence table to show what corrispondence has been sent to various companies.

However, when I tried this for our latest mailing it only worked for 52
of
348 the records.
The QryICTMassDistr ibution3 query, links several tables, and returns 348 records when run normally but in the code below the recordset only
seems to
have 52 records.

Can anyone suggest where I have gone wrong?

Many thanks
JM

the code:

Private Sub Command0_Click( )

Dim cnxn As ADODB.Connectio n
Dim rs As ADODB.Recordset
Set cnxn = CurrentProject. Connection
Set rs = New ADODB.Recordset
Set linktable = New ADODB.Recordset
Dim count As Integer
rs.Open "Select Count(*) As MatchCount FROM QryICTMassDistr ibution3",
cnxn
linktable.Open "TblCompanyId_C orrespondence", cnxn, adOpenKeyset,
adLockOptimisti c
rs.MoveFirst
MsgBox "you are about to process " & rs!MatchCount & " records"
count = 0
While Not rs.EOF
count = count + 1
linktable.AddNe w
linktable.Field s("CompanyId" ) = rs.Fields("Comp anyId")
linktable.Field s("Corespondenc eId") = Text5.Value
rs.MoveNext
Wend
rs.Close
MsgBox count & " records added to corrispondence table"

Set rs = Nothing
linktable.Updat e
linktable.Close
Rem Set linktable = Nothing
End Sub



Nov 13 '05 #5
Jan
Hiya

What you described is what I had originally! I had added the matchcount as
..recordcount only returns 1! Reading on the net it was suggested that there
is some timing issues and matchcount was recomended, i didnt realise that
would only return one record! :(

I have changed my code back to the original as shown below.

I now get told it will process 1 record, but it then processes 52! There is
still a difference between the number of records QryMassICTDist5 returns
when I put Select * FROM QryMassICTDist5 in an SQL view and then view the
records returned i get 345!!!!!

I appreciate your help :)

I now have:
rivate Sub Command0_Click( )

Dim cnxn As ADODB.Connectio n
Dim rs As ADODB.Recordset
Set cnxn = CurrentProject. Connection
Set rs = New ADODB.Recordset
Set linktable = New ADODB.Recordset

rs.Open "Select * FROM QryMassICTDist5 ", cnxn
linktable.Open "TblSchoolId_Co rrespondence", cnxn, adOpenKeyset,
adLockOptimisti c

rs.MoveFirst
MsgBox "you are about to process " & rs.RecordCount & " records"
While Not rs.EOF
linktable.AddNe w
linktable.Field s("SchoolId") = rs.Fields("Scho olId")
linktable.Field s("Corespondenc eId") = Text5.Value
linktable.Updat e
rs.MoveNext
Wend
rs.Close
Set rs = Nothing
linktable.Close
End Sub

"Rob Oldfield" <bl**@blah.co m> wrote in message
news:eJ******** ******@tk2msftn gp13.phx.gbl...
(apologies for accidentally mailing this to your reply address)

I'm afraid that whatever code you have that is working, it's fundamentally
different from this code.

If you take the SQL statement Select Count(*) As MatchCount FROM
QryICTMassDistr ibution3 and paste it into the SQL window of a query, and
then switch to the datasheet, then you'll get a single record, single
field
display showing you how many records you have.

You'd be better off just replacing that with Select * FROM
QryICTMassDistr ibution3... that will then give you a loop that works.
You'll be able to use rs.recordcount to return the number of records
returned for your message.

On the .update question then yes, you should have it run inside the loop
as
you suggest.

And regarding the idea to use an append query, you should be appending on
to
a table - ensuring that the values you're writing into foreign key fields
are correct. That would get around the recordset not being updatable.

"Jan" <Ja************ *@hotmail.com> wrote in message
news:d3******** **@newsg2.svr.p ol.co.uk...
Hi

Thanks for the previous comments.

As you may guess programming in VBA isn't my strong point!

I'm not sure I understand why you are saying rs.open only returns one
record? I have actually used this code in the past with different queries
that return 50 to 60 records and it has worked.

How do I make it return all the records?

I cant use an append query as the relationships are too complex and the
query ends up saying 'record set is not updateable'. Hence I decided the
easiest way would be to simple loop through the records in the query and

add
their ID together with a correspondence to a new table.

I have got a .update at the end of the code, are you saying it should be

in
the loop with the .addnew?

Many thanks for the help
JM

"Rob Oldfield" <bl**@blah.co m> wrote in message
news:O8******** ******@TK2MSFTN GP10.phx.gbl...
> To be honest, I can't see how it does anything at all.
>
> The rs.open will return a recordset with a single record containing a
> count
> value. Looping through that recordset will therefore loop just once.
> The .addnew needs a corresponding .update in order to tell the
> linktable
> recordset to actually retain the record you've added.
>
> Have you tried dropping a breakpoint in there and following your logic
> through?
>
> Why not just use an append query? It'd be a great deal easier.
>
>
> "Jan" <Ja************ *@hotmail.com> wrote in message
> news:d3******** **@news8.svr.po l.co.uk...
>> Hi
>>
>> I have a database that I use to keep track of the sales promotions
>> that
>> we
>> send to companies.
>>
>> I normally send a mailing based on a subset of the companies in the
> database
>> (found using the query: QryICTMassDistr ibution3) , I then use a form and >> the code below to create a new record in the corrispondence table to show >> what corrispondence has been sent to various companies.
>>
>> However, when I tried this for our latest mailing it only worked for
>> 52
>> of
>> 348 the records.
>> The QryICTMassDistr ibution3 query, links several tables, and returns 348 >> records when run normally but in the code below the recordset only seems > to
>> have 52 records.
>>
>> Can anyone suggest where I have gone wrong?
>>
>> Many thanks
>> JM
>>
>> the code:
>>
>> Private Sub Command0_Click( )
>>
>> Dim cnxn As ADODB.Connectio n
>> Dim rs As ADODB.Recordset
>> Set cnxn = CurrentProject. Connection
>> Set rs = New ADODB.Recordset
>> Set linktable = New ADODB.Recordset
>> Dim count As Integer
>>
>>
>> rs.Open "Select Count(*) As MatchCount FROM QryICTMassDistr ibution3",
>> cnxn
>> linktable.Open "TblCompanyId_C orrespondence", cnxn, adOpenKeyset,
>> adLockOptimisti c
>> rs.MoveFirst
>> MsgBox "you are about to process " & rs!MatchCount & " records"
>> count = 0
>> While Not rs.EOF
>> count = count + 1
>> linktable.AddNe w
>> linktable.Field s("CompanyId" ) = rs.Fields("Comp anyId")
>> linktable.Field s("Corespondenc eId") = Text5.Value
>> rs.MoveNext
>> Wend
>> rs.Close
>> MsgBox count & " records added to corrispondence table"
>>
>> Set rs = Nothing
>> linktable.Updat e
>> linktable.Close
>> Rem Set linktable = Nothing
>> End Sub
>>
>>
>>
>
>



Nov 13 '05 #6
RecordCount isn't accurate until you've read all of the records in the
recordset.

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

"Jan" <Ja************ *@hotmail.com> wrote in message
news:d3******** **@newsg1.svr.p ol.co.uk...
Hiya

What you described is what I had originally! I had added the matchcount as
.recordcount only returns 1! Reading on the net it was suggested that
there is some timing issues and matchcount was recomended, i didnt realise
that would only return one record! :(

I have changed my code back to the original as shown below.

I now get told it will process 1 record, but it then processes 52! There
is still a difference between the number of records QryMassICTDist5
returns when I put Select * FROM QryMassICTDist5 in an SQL view and then
view the records returned i get 345!!!!!

I appreciate your help :)

I now have:
rivate Sub Command0_Click( )

Dim cnxn As ADODB.Connectio n
Dim rs As ADODB.Recordset
Set cnxn = CurrentProject. Connection
Set rs = New ADODB.Recordset
Set linktable = New ADODB.Recordset

rs.Open "Select * FROM QryMassICTDist5 ", cnxn
linktable.Open "TblSchoolId_Co rrespondence", cnxn, adOpenKeyset,
adLockOptimisti c

rs.MoveFirst
MsgBox "you are about to process " & rs.RecordCount & " records"
While Not rs.EOF
linktable.AddNe w
linktable.Field s("SchoolId") = rs.Fields("Scho olId")
linktable.Field s("Corespondenc eId") = Text5.Value
linktable.Updat e
rs.MoveNext
Wend
rs.Close
Set rs = Nothing
linktable.Close
End Sub

"Rob Oldfield" <bl**@blah.co m> wrote in message
news:eJ******** ******@tk2msftn gp13.phx.gbl...
(apologies for accidentally mailing this to your reply address)

I'm afraid that whatever code you have that is working, it's
fundamentally
different from this code.

If you take the SQL statement Select Count(*) As MatchCount FROM
QryICTMassDistr ibution3 and paste it into the SQL window of a query, and
then switch to the datasheet, then you'll get a single record, single
field
display showing you how many records you have.

You'd be better off just replacing that with Select * FROM
QryICTMassDistr ibution3... that will then give you a loop that works.
You'll be able to use rs.recordcount to return the number of records
returned for your message.

On the .update question then yes, you should have it run inside the loop
as
you suggest.

And regarding the idea to use an append query, you should be appending on
to
a table - ensuring that the values you're writing into foreign key fields
are correct. That would get around the recordset not being updatable.

"Jan" <Ja************ *@hotmail.com> wrote in message
news:d3******** **@newsg2.svr.p ol.co.uk...
Hi

Thanks for the previous comments.

As you may guess programming in VBA isn't my strong point!

I'm not sure I understand why you are saying rs.open only returns one
record? I have actually used this code in the past with different
queries
that return 50 to 60 records and it has worked.

How do I make it return all the records?

I cant use an append query as the relationships are too complex and the
query ends up saying 'record set is not updateable'. Hence I decided the
easiest way would be to simple loop through the records in the query and

add
their ID together with a correspondence to a new table.

I have got a .update at the end of the code, are you saying it should be

in
the loop with the .addnew?

Many thanks for the help
JM

"Rob Oldfield" <bl**@blah.co m> wrote in message
news:O8******** ******@TK2MSFTN GP10.phx.gbl...
> To be honest, I can't see how it does anything at all.
>
> The rs.open will return a recordset with a single record containing a
> count
> value. Looping through that recordset will therefore loop just once.
> The .addnew needs a corresponding .update in order to tell the
> linktable
> recordset to actually retain the record you've added.
>
> Have you tried dropping a breakpoint in there and following your logic
> through?
>
> Why not just use an append query? It'd be a great deal easier.
>
>
> "Jan" <Ja************ *@hotmail.com> wrote in message
> news:d3******** **@news8.svr.po l.co.uk...
>> Hi
>>
>> I have a database that I use to keep track of the sales promotions
>> that
>> we
>> send to companies.
>>
>> I normally send a mailing based on a subset of the companies in the
> database
>> (found using the query: QryICTMassDistr ibution3) , I then use a form

and
>> the code below to create a new record in the corrispondence table to

show
>> what corrispondence has been sent to various companies.
>>
>> However, when I tried this for our latest mailing it only worked for
>> 52
>> of
>> 348 the records.
>> The QryICTMassDistr ibution3 query, links several tables, and returns

348
>> records when run normally but in the code below the recordset only

seems
> to
>> have 52 records.
>>
>> Can anyone suggest where I have gone wrong?
>>
>> Many thanks
>> JM
>>
>> the code:
>>
>> Private Sub Command0_Click( )
>>
>> Dim cnxn As ADODB.Connectio n
>> Dim rs As ADODB.Recordset
>> Set cnxn = CurrentProject. Connection
>> Set rs = New ADODB.Recordset
>> Set linktable = New ADODB.Recordset
>> Dim count As Integer
>>
>>
>> rs.Open "Select Count(*) As MatchCount FROM QryICTMassDistr ibution3",
>> cnxn
>> linktable.Open "TblCompanyId_C orrespondence", cnxn, adOpenKeyset,
>> adLockOptimisti c
>> rs.MoveFirst
>> MsgBox "you are about to process " & rs!MatchCount & " records"
>> count = 0
>> While Not rs.EOF
>> count = count + 1
>> linktable.AddNe w
>> linktable.Field s("CompanyId" ) = rs.Fields("Comp anyId")
>> linktable.Field s("Corespondenc eId") = Text5.Value
>> rs.MoveNext
>> Wend
>> rs.Close
>> MsgBox count & " records added to corrispondence table"
>>
>> Set rs = Nothing
>> linktable.Updat e
>> linktable.Close
>> Rem Set linktable = Nothing
>> End Sub
>>
>>
>>
>
>



Nov 13 '05 #7
ADO uses a forward only cursor for recordsets by default.
change:
rs.Open "Select * FROM QryMassICTDist5 ", cnxn
to:
rs.Open "Select * FROM QryMassICTDist5 ", cnxn, adOpenKeyset

Then you will at least get a recordcount. I don't know why the discrepancy
in the number of records processed, but perhaps getting a recordcount might
give you a clue.

--
Randy Harris
(tech at promail dot com)
"Jan" <Ja************ *@hotmail.com> wrote in message
news:d3******** **@newsg1.svr.p ol.co.uk...
Hiya

What you described is what I had originally! I had added the matchcount as
.recordcount only returns 1! Reading on the net it was suggested that there is some timing issues and matchcount was recomended, i didnt realise that
would only return one record! :(

I have changed my code back to the original as shown below.

I now get told it will process 1 record, but it then processes 52! There is still a difference between the number of records QryMassICTDist5 returns
when I put Select * FROM QryMassICTDist5 in an SQL view and then view the
records returned i get 345!!!!!

I appreciate your help :)

I now have:
rivate Sub Command0_Click( )

Dim cnxn As ADODB.Connectio n
Dim rs As ADODB.Recordset
Set cnxn = CurrentProject. Connection
Set rs = New ADODB.Recordset
Set linktable = New ADODB.Recordset

rs.Open "Select * FROM QryMassICTDist5 ", cnxn
linktable.Open "TblSchoolId_Co rrespondence", cnxn, adOpenKeyset,
adLockOptimisti c

rs.MoveFirst
MsgBox "you are about to process " & rs.RecordCount & " records"
While Not rs.EOF
linktable.AddNe w
linktable.Field s("SchoolId") = rs.Fields("Scho olId")
linktable.Field s("Corespondenc eId") = Text5.Value
linktable.Updat e
rs.MoveNext
Wend
rs.Close
Set rs = Nothing
linktable.Close
End Sub

"Rob Oldfield" <bl**@blah.co m> wrote in message
news:eJ******** ******@tk2msftn gp13.phx.gbl...
(apologies for accidentally mailing this to your reply address)

I'm afraid that whatever code you have that is working, it's fundamentally different from this code.

If you take the SQL statement Select Count(*) As MatchCount FROM
QryICTMassDistr ibution3 and paste it into the SQL window of a query, and
then switch to the datasheet, then you'll get a single record, single
field
display showing you how many records you have.

You'd be better off just replacing that with Select * FROM
QryICTMassDistr ibution3... that will then give you a loop that works.
You'll be able to use rs.recordcount to return the number of records
returned for your message.

On the .update question then yes, you should have it run inside the loop
as
you suggest.

And regarding the idea to use an append query, you should be appending on to
a table - ensuring that the values you're writing into foreign key fields are correct. That would get around the recordset not being updatable.

"Jan" <Ja************ *@hotmail.com> wrote in message
news:d3******** **@newsg2.svr.p ol.co.uk...
Hi

Thanks for the previous comments.

As you may guess programming in VBA isn't my strong point!

I'm not sure I understand why you are saying rs.open only returns one
record? I have actually used this code in the past with different queries that return 50 to 60 records and it has worked.

How do I make it return all the records?

I cant use an append query as the relationships are too complex and the
query ends up saying 'record set is not updateable'. Hence I decided the easiest way would be to simple loop through the records in the query and
add
their ID together with a correspondence to a new table.

I have got a .update at the end of the code, are you saying it should
be in
the loop with the .addnew?

Many thanks for the help
JM

"Rob Oldfield" <bl**@blah.co m> wrote in message
news:O8******** ******@TK2MSFTN GP10.phx.gbl...
> To be honest, I can't see how it does anything at all.
>
> The rs.open will return a recordset with a single record containing a
> count
> value. Looping through that recordset will therefore loop just once.
> The .addnew needs a corresponding .update in order to tell the
> linktable
> recordset to actually retain the record you've added.
>
> Have you tried dropping a breakpoint in there and following your
logic > through?
>
> Why not just use an append query? It'd be a great deal easier.
>
>
> "Jan" <Ja************ *@hotmail.com> wrote in message
> news:d3******** **@news8.svr.po l.co.uk...
>> Hi
>>
>> I have a database that I use to keep track of the sales promotions
>> that
>> we
>> send to companies.
>>
>> I normally send a mailing based on a subset of the companies in the
> database
>> (found using the query: QryICTMassDistr ibution3) , I then use a form and
>> the code below to create a new record in the corrispondence table to

show
>> what corrispondence has been sent to various companies.
>>
>> However, when I tried this for our latest mailing it only worked for
>> 52
>> of
>> 348 the records.
>> The QryICTMassDistr ibution3 query, links several tables, and
returns 348
>> records when run normally but in the code below the recordset only

seems
> to
>> have 52 records.
>>
>> Can anyone suggest where I have gone wrong?
>>
>> Many thanks
>> JM
>>
>> the code:
>>
>> Private Sub Command0_Click( )
>>
>> Dim cnxn As ADODB.Connectio n
>> Dim rs As ADODB.Recordset
>> Set cnxn = CurrentProject. Connection
>> Set rs = New ADODB.Recordset
>> Set linktable = New ADODB.Recordset
>> Dim count As Integer
>>
>>
>> rs.Open "Select Count(*) As MatchCount FROM

QryICTMassDistr ibution3", >> cnxn
>> linktable.Open "TblCompanyId_C orrespondence", cnxn, adOpenKeyset,
>> adLockOptimisti c
>> rs.MoveFirst
>> MsgBox "you are about to process " & rs!MatchCount & " records"
>> count = 0
>> While Not rs.EOF
>> count = count + 1
>> linktable.AddNe w
>> linktable.Field s("CompanyId" ) = rs.Fields("Comp anyId")
>> linktable.Field s("Corespondenc eId") = Text5.Value
>> rs.MoveNext
>> Wend
>> rs.Close
>> MsgBox count & " records added to corrispondence table"
>>
>> Set rs = Nothing
>> linktable.Updat e
>> linktable.Close
>> Rem Set linktable = Nothing
>> End Sub
>>
>>
>>
>
>



Nov 13 '05 #8
Jan
Thank you for this.
I now get a recordcount of 52.
Can anyone suggest why there is this discrepancy between the recordcount
compared to the qbe?
Many thanks
Jan

"Randy Harris" <ra***@nospam.c om> wrote in message
news:eD******** ******@TK2MSFTN GP09.phx.gbl...
ADO uses a forward only cursor for recordsets by default.
change:
rs.Open "Select * FROM QryMassICTDist5 ", cnxn
to:
rs.Open "Select * FROM QryMassICTDist5 ", cnxn, adOpenKeyset

Then you will at least get a recordcount. I don't know why the
discrepancy
in the number of records processed, but perhaps getting a recordcount
might
give you a clue.

--
Randy Harris
(tech at promail dot com)
"Jan" <Ja************ *@hotmail.com> wrote in message
news:d3******** **@newsg1.svr.p ol.co.uk...
Hiya

What you described is what I had originally! I had added the matchcount
as
.recordcount only returns 1! Reading on the net it was suggested that

there
is some timing issues and matchcount was recomended, i didnt realise that
would only return one record! :(

I have changed my code back to the original as shown below.

I now get told it will process 1 record, but it then processes 52! There

is
still a difference between the number of records QryMassICTDist5 returns
when I put Select * FROM QryMassICTDist5 in an SQL view and then view the
records returned i get 345!!!!!

I appreciate your help :)

I now have:
rivate Sub Command0_Click( )

Dim cnxn As ADODB.Connectio n
Dim rs As ADODB.Recordset
Set cnxn = CurrentProject. Connection
Set rs = New ADODB.Recordset
Set linktable = New ADODB.Recordset

rs.Open "Select * FROM QryMassICTDist5 ", cnxn
linktable.Open "TblSchoolId_Co rrespondence", cnxn, adOpenKeyset,
adLockOptimisti c

rs.MoveFirst
MsgBox "you are about to process " & rs.RecordCount & " records"
While Not rs.EOF
linktable.AddNe w
linktable.Field s("SchoolId") = rs.Fields("Scho olId")
linktable.Field s("Corespondenc eId") = Text5.Value
linktable.Updat e
rs.MoveNext
Wend
rs.Close
Set rs = Nothing
linktable.Close
End Sub

"Rob Oldfield" <bl**@blah.co m> wrote in message
news:eJ******** ******@tk2msftn gp13.phx.gbl...
> (apologies for accidentally mailing this to your reply address)
>
> I'm afraid that whatever code you have that is working, it's fundamentally > different from this code.
>
> If you take the SQL statement Select Count(*) As MatchCount FROM
> QryICTMassDistr ibution3 and paste it into the SQL window of a query,
> and
> then switch to the datasheet, then you'll get a single record, single
> field
> display showing you how many records you have.
>
> You'd be better off just replacing that with Select * FROM
> QryICTMassDistr ibution3... that will then give you a loop that works.
> You'll be able to use rs.recordcount to return the number of records
> returned for your message.
>
> On the .update question then yes, you should have it run inside the
> loop
> as
> you suggest.
>
> And regarding the idea to use an append query, you should be appending on > to
> a table - ensuring that the values you're writing into foreign key fields > are correct. That would get around the recordset not being updatable.
>
>
>
> "Jan" <Ja************ *@hotmail.com> wrote in message
> news:d3******** **@newsg2.svr.p ol.co.uk...
>> Hi
>>
>> Thanks for the previous comments.
>>
>> As you may guess programming in VBA isn't my strong point!
>>
>> I'm not sure I understand why you are saying rs.open only returns one
>> record? I have actually used this code in the past with different queries >> that return 50 to 60 records and it has worked.
>>
>> How do I make it return all the records?
>>
>> I cant use an append query as the relationships are too complex and
>> the
>> query ends up saying 'record set is not updateable'. Hence I decided the >> easiest way would be to simple loop through the records in the query and > add
>> their ID together with a correspondence to a new table.
>>
>> I have got a .update at the end of the code, are you saying it should be > in
>> the loop with the .addnew?
>>
>> Many thanks for the help
>> JM
>>
>> "Rob Oldfield" <bl**@blah.co m> wrote in message
>> news:O8******** ******@TK2MSFTN GP10.phx.gbl...
>> > To be honest, I can't see how it does anything at all.
>> >
>> > The rs.open will return a recordset with a single record containing
>> > a
>> > count
>> > value. Looping through that recordset will therefore loop just
>> > once.
>> > The .addnew needs a corresponding .update in order to tell the
>> > linktable
>> > recordset to actually retain the record you've added.
>> >
>> > Have you tried dropping a breakpoint in there and following your logic >> > through?
>> >
>> > Why not just use an append query? It'd be a great deal easier.
>> >
>> >
>> > "Jan" <Ja************ *@hotmail.com> wrote in message
>> > news:d3******** **@news8.svr.po l.co.uk...
>> >> Hi
>> >>
>> >> I have a database that I use to keep track of the sales promotions
>> >> that
>> >> we
>> >> send to companies.
>> >>
>> >> I normally send a mailing based on a subset of the companies in the
>> > database
>> >> (found using the query: QryICTMassDistr ibution3) , I then use a form > and
>> >> the code below to create a new record in the corrispondence table
>> >> to
> show
>> >> what corrispondence has been sent to various companies.
>> >>
>> >> However, when I tried this for our latest mailing it only worked
>> >> for
>> >> 52
>> >> of
>> >> 348 the records.
>> >> The QryICTMassDistr ibution3 query, links several tables, and returns > 348
>> >> records when run normally but in the code below the recordset only
> seems
>> > to
>> >> have 52 records.
>> >>
>> >> Can anyone suggest where I have gone wrong?
>> >>
>> >> Many thanks
>> >> JM
>> >>
>> >> the code:
>> >>
>> >> Private Sub Command0_Click( )
>> >>
>> >> Dim cnxn As ADODB.Connectio n
>> >> Dim rs As ADODB.Recordset
>> >> Set cnxn = CurrentProject. Connection
>> >> Set rs = New ADODB.Recordset
>> >> Set linktable = New ADODB.Recordset
>> >> Dim count As Integer
>> >>
>> >>
>> >> rs.Open "Select Count(*) As MatchCount FROM QryICTMassDistr ibution3", >> >> cnxn
>> >> linktable.Open "TblCompanyId_C orrespondence", cnxn, adOpenKeyset,
>> >> adLockOptimisti c
>> >> rs.MoveFirst
>> >> MsgBox "you are about to process " & rs!MatchCount & " records"
>> >> count = 0
>> >> While Not rs.EOF
>> >> count = count + 1
>> >> linktable.AddNe w
>> >> linktable.Field s("CompanyId" ) = rs.Fields("Comp anyId")
>> >> linktable.Field s("Corespondenc eId") = Text5.Value
>> >> rs.MoveNext
>> >> Wend
>> >> rs.Close
>> >> MsgBox count & " records added to corrispondence table"
>> >>
>> >> Set rs = Nothing
>> >> linktable.Updat e
>> >> linktable.Close
>> >> Rem Set linktable = Nothing
>> >> End Sub
>> >>
>> >>
>> >>
>> >
>> >
>>
>>
>
>



Nov 13 '05 #9
Jan
Hi

Have been looking at the append query. Not sure this meets our need even if
I can overcome the non updatable recordset problem. From my understanding;
an append query adds records from one table into another. What we need to do
is to add the ID's from a query into another table along with some fixed
data. The fixed data being the ID of the correspondence being sent. So for
example we might have a query that returns customers: 3, 7, 10,11,15 that
have been sent mailshot type 17, we would thus want in our link table new
records with:
customerID,mail shotID
3,17
7,17
10,17
11,17
15,17

The only way I can think of doing this is via code.

JD
"Rob Oldfield" <bl**@blah.co m> wrote in message
news:O8******** ******@TK2MSFTN GP10.phx.gbl...
To be honest, I can't see how it does anything at all.

The rs.open will return a recordset with a single record containing a
count
value. Looping through that recordset will therefore loop just once.
The .addnew needs a corresponding .update in order to tell the linktable
recordset to actually retain the record you've added.

Have you tried dropping a breakpoint in there and following your logic
through?

Why not just use an append query? It'd be a great deal easier.
"Jan" <Ja************ *@hotmail.com> wrote in message
news:d3******** **@news8.svr.po l.co.uk...
Hi

I have a database that I use to keep track of the sales promotions that
we
send to companies.

I normally send a mailing based on a subset of the companies in the

database
(found using the query: QryICTMassDistr ibution3) , I then use a form and
the code below to create a new record in the corrispondence table to show
what corrispondence has been sent to various companies.

However, when I tried this for our latest mailing it only worked for 52
of
348 the records.
The QryICTMassDistr ibution3 query, links several tables, and returns 348
records when run normally but in the code below the recordset only seems

to
have 52 records.

Can anyone suggest where I have gone wrong?

Many thanks
JM

the code:

Private Sub Command0_Click( )

Dim cnxn As ADODB.Connectio n
Dim rs As ADODB.Recordset
Set cnxn = CurrentProject. Connection
Set rs = New ADODB.Recordset
Set linktable = New ADODB.Recordset
Dim count As Integer
rs.Open "Select Count(*) As MatchCount FROM QryICTMassDistr ibution3",
cnxn
linktable.Open "TblCompanyId_C orrespondence", cnxn, adOpenKeyset,
adLockOptimisti c
rs.MoveFirst
MsgBox "you are about to process " & rs!MatchCount & " records"
count = 0
While Not rs.EOF
count = count + 1
linktable.AddNe w
linktable.Field s("CompanyId" ) = rs.Fields("Comp anyId")
linktable.Field s("Corespondenc eId") = Text5.Value
rs.MoveNext
Wend
rs.Close
MsgBox count & " records added to corrispondence table"

Set rs = Nothing
linktable.Updat e
linktable.Close
Rem Set linktable = Nothing
End Sub


Nov 13 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
3231
by: shank | last post by:
I have a recordset that contains multiple records of product a user is purchasing. For clarity, I converted the recordset fields to variables. I need to take that entire recordset and insert it into another table on a remote server. The below code only inserts 1 record. How do I change the code to get all records inserted? thanks! <% Dim DataConn2 Set DataConn2 = Server.CreateObject("ADODB.Connection")
6
2506
by: Robin S. | last post by:
**Eric and Salad - thank you both for the polite kick in the butt. I hope I've done a better job of explaining myself below. I am trying to produce a form to add products to a table (new products). Tables: tblCategoryDetails CategoryID SpecID
7
5384
by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available from clicking on many of the available topics (mostly methods but some properties are also unavailable). This same problem occurs with many, if not most, keywords. Is there any way I can activate these "missing" help topics? HELP!
10
3736
by: Lyn | last post by:
I have a form set to Single Form mode with which I can cycle through the records in a table via Next and Previous buttons. To avoid users pressing the Previous button on the first record and the Next button on the last record, I would like to disable one or both buttons when the first and/or last record is displayed. I am not sure how to do this when the RecordSource is simply the table. I know that if the record source were a...
2
28322
by: Nono | last post by:
Hello, I have an Access Database that I want to update using an Excel spreadsheet. When it is new reccords, I know how to do it. Nevertheless when I want to complete the information on a certain row of records which already exist, or if I would like to update it (ie: partially change certain records on a row), I do not know how to :
10
6730
by: Robert | last post by:
How do you get an accurate count of the number of records returned from a query when using linked tables. I have an access 2003 database as a front end to another access 2003 database that contains only tables. I have linked the tables for the front end to the back end database. I am trying to set the recordsource of a form to a query established by the user to narrow the scope but I don't want to display the form if there are no...
4
1913
by: D | last post by:
I think this is a simple fix, but a second set of eyes could certainly help. Here is the error in it's entirety followed by my search criteria code. Any suggestions? Microsoft JET Database Engine error '80040e14' Syntax error (missing operator) in query expression 'LimitDate LIKE #7/18# WHERE skill in (select skill from tbl_timelimit where skill LIKE '%sales%' ) AND LimitDate >= #7/18/2006#'.
6
5478
by: InnoCreate | last post by:
Hi everyone. I've recently written a classic asp website which uses an MS Access datasource. I know this is less than an ideal data source as it has limited functionality. I have a search form on my website which allows users to define parameters and return results accordingly. The problem i have is a need to return these results in a random order each time. With SQLServer i know NEWID() would do the trick - used this many times before...
6
2775
by: gerbski | last post by:
Hi all, I am relatively new to ADO, but up to now I got things working the way I wanted. But now I've run into somethng really annoying. I am working in MS Access. I am using an Access frontend separately from a backend. The tables from the backend database are linked in the frontend database. In the frontend there is a Form with a listbox in it. The listbox rowsource is a query that selects all the records from a (linked)
0
10148
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9823
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8822
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3528
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.