Filling continuous form with VBA recordset

M

mltullos

I am having trouble populating a continuous form from a recordset in VBA. I
am familiar with population single forms but am having trouble with
incrementing/indexing the continuous form
A portion of my code is
While (Not (rs.EOF))
*** set values and controls here ***
DoCmd.GoToRecord , , acNewRec
rs.MoveNext 'incrementing recordset index
Wend
This resulted in only the last record being displayed. What command is
needed to add a new record to the continous form ?
 
G

Graham Mandeno

Hi mltullos

A continuous form is, by definition, bound to a RecordSource (otherwise
there would be at most one row!)

You "populate" it by setting the form's RecordSource to the table or query
that contains your data, and setting the ControlSource of the controls
(textboxes etc) to the names of the fields in the RecordSource.

No code is required at all.
 
M

mltullos

Thanks for the response.

Maybe there is another way to accomplish what I want to do other than a
continuous form.

I've used SQL in VBA to create a temporary table of the data I want included
in the continuous form. Using the temporary table as the record source for
the continuous form does not give me the control I'm wanting (or at least I
don't think it does).
I created a record set, sorted and formatted it comparable to the sorting
and grouping feature in reports and saved it to a temporary table.
The table consists of:
four fields I want displayed (unit, iteration, system, status)
two fields to display as control tip text for iteration and system
one field with the record number to be manipulated to alternate row color
one field containing the index/key number from the original table - on
click VBA code will open a different form with the full record.

I've attempted an unbound continuous form but I'm not quite sure how Access
fills bound continuous forms. I assumed Access would create a recordset from
the record source, populate the fields in one row of the continuous form, and
then increment the recordset (ie. rs.movenext) and increment or initialize a
new row on the continuous form. Is there any way to to increment or
initialize a new row or is it possible to set the control tip text to a table
field in a bound continuous form?
Any suggestions?

Graham Mandeno said:
Hi mltullos

A continuous form is, by definition, bound to a RecordSource (otherwise
there would be at most one row!)

You "populate" it by setting the form's RecordSource to the table or query
that contains your data, and setting the ControlSource of the controls
(textboxes etc) to the names of the fields in the RecordSource.

No code is required at all.
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


mltullos said:
I am having trouble populating a continuous form from a recordset in VBA.
I
am familiar with population single forms but am having trouble with
incrementing/indexing the continuous form
A portion of my code is
While (Not (rs.EOF))
*** set values and controls here ***
DoCmd.GoToRecord , , acNewRec
rs.MoveNext 'incrementing recordset index
Wend
This resulted in only the last record being displayed. What command is
needed to add a new record to the continous form ?
 
G

Graham Mandeno

Hello again

Unless I'm missing something here, there is no need for a temporary table.

Create a query comprising data selected from your original table(s). Set
the selection criteria (WHERE clause) and the sorting criteria (ORDER BY
clause) as required. Then make this query the RecordSource of your
continuous form. If you have some compelling reason for using a temporary
table, then use that table as your RecordSource.

As I said, there is no purpose for an unbound continuous form as it would
display no rows. To answer your question, Access fills bound continuous
forms by creating one instance of the detail section for every record in the
bound recordset. Bound controls are filled with the values from the
ControlSource fields/expressions from the corresponding record in the
recordset. Unbound controls have the same value in every row.

Other control properties, such as BackColor, Width, ControlTipText, etc, are
the same for every instance of the control, whether or not the control is
bound. The only way to give individual properties to controls in different
rows is via the limited capabilities of conditional formatting.

For this reason, I can't see any way to change the ControlTipText depending
on which record is currently under the mouse.
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


mltullos said:
Thanks for the response.

Maybe there is another way to accomplish what I want to do other than a
continuous form.

I've used SQL in VBA to create a temporary table of the data I want
included
in the continuous form. Using the temporary table as the record source
for
the continuous form does not give me the control I'm wanting (or at least
I
don't think it does).
I created a record set, sorted and formatted it comparable to the sorting
and grouping feature in reports and saved it to a temporary table.
The table consists of:
four fields I want displayed (unit, iteration, system, status)
two fields to display as control tip text for iteration and system
one field with the record number to be manipulated to alternate row color
one field containing the index/key number from the original table - on
click VBA code will open a different form with the full record.

I've attempted an unbound continuous form but I'm not quite sure how
Access
fills bound continuous forms. I assumed Access would create a recordset
from
the record source, populate the fields in one row of the continuous form,
and
then increment the recordset (ie. rs.movenext) and increment or initialize
a
new row on the continuous form. Is there any way to to increment or
initialize a new row or is it possible to set the control tip text to a
table
field in a bound continuous form?
Any suggestions?

Graham Mandeno said:
Hi mltullos

A continuous form is, by definition, bound to a RecordSource (otherwise
there would be at most one row!)

You "populate" it by setting the form's RecordSource to the table or
query
that contains your data, and setting the ControlSource of the controls
(textboxes etc) to the names of the fields in the RecordSource.

No code is required at all.
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


mltullos said:
I am having trouble populating a continuous form from a recordset in
VBA.
I
am familiar with population single forms but am having trouble with
incrementing/indexing the continuous form
A portion of my code is
While (Not (rs.EOF))
*** set values and controls here ***
DoCmd.GoToRecord , , acNewRec
rs.MoveNext 'incrementing recordset index
Wend
This resulted in only the last record being displayed. What command is
needed to add a new record to the continous form ?
 
M

mltullos

Thanks again for the help. This is something I will have to put off until a
later time. With a bound continuous form I'm able to display the fields I
want and set the controltip text using a combination of on current and mouse
move code but it requires a mouseclick to make the record current to update
the controltiip text. Without a mouseclick, the controltip text does not
update - which will confuse the users.

Thanks

Graham Mandeno said:
Hello again

Unless I'm missing something here, there is no need for a temporary table.

Create a query comprising data selected from your original table(s). Set
the selection criteria (WHERE clause) and the sorting criteria (ORDER BY
clause) as required. Then make this query the RecordSource of your
continuous form. If you have some compelling reason for using a temporary
table, then use that table as your RecordSource.

As I said, there is no purpose for an unbound continuous form as it would
display no rows. To answer your question, Access fills bound continuous
forms by creating one instance of the detail section for every record in the
bound recordset. Bound controls are filled with the values from the
ControlSource fields/expressions from the corresponding record in the
recordset. Unbound controls have the same value in every row.

Other control properties, such as BackColor, Width, ControlTipText, etc, are
the same for every instance of the control, whether or not the control is
bound. The only way to give individual properties to controls in different
rows is via the limited capabilities of conditional formatting.

For this reason, I can't see any way to change the ControlTipText depending
on which record is currently under the mouse.
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


mltullos said:
Thanks for the response.

Maybe there is another way to accomplish what I want to do other than a
continuous form.

I've used SQL in VBA to create a temporary table of the data I want
included
in the continuous form. Using the temporary table as the record source
for
the continuous form does not give me the control I'm wanting (or at least
I
don't think it does).
I created a record set, sorted and formatted it comparable to the sorting
and grouping feature in reports and saved it to a temporary table.
The table consists of:
four fields I want displayed (unit, iteration, system, status)
two fields to display as control tip text for iteration and system
one field with the record number to be manipulated to alternate row color
one field containing the index/key number from the original table - on
click VBA code will open a different form with the full record.

I've attempted an unbound continuous form but I'm not quite sure how
Access
fills bound continuous forms. I assumed Access would create a recordset
from
the record source, populate the fields in one row of the continuous form,
and
then increment the recordset (ie. rs.movenext) and increment or initialize
a
new row on the continuous form. Is there any way to to increment or
initialize a new row or is it possible to set the control tip text to a
table
field in a bound continuous form?
Any suggestions?

Graham Mandeno said:
Hi mltullos

A continuous form is, by definition, bound to a RecordSource (otherwise
there would be at most one row!)

You "populate" it by setting the form's RecordSource to the table or
query
that contains your data, and setting the ControlSource of the controls
(textboxes etc) to the names of the fields in the RecordSource.

No code is required at all.
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


I am having trouble populating a continuous form from a recordset in
VBA.
I
am familiar with population single forms but am having trouble with
incrementing/indexing the continuous form
A portion of my code is
While (Not (rs.EOF))
*** set values and controls here ***
DoCmd.GoToRecord , , acNewRec
rs.MoveNext 'incrementing recordset index
Wend
This resulted in only the last record being displayed. What command is
needed to add a new record to the continous form ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top