Adding Feilds To Form Programaticaly A97

K

Kahuna

Hi Folks

I have a form used to select criteria which is then used to build an SQL
string.

The fields I already have in the form make up the selection for what would
be one line in a Query window (resolving into the AND portion of the SQL
string). Each of these fields relate to a table entry.

My challenge is to programmatically add another section to the form with a
replica of the fields in the first section - this will resolve into the OR
portion of the string. When these new fields are populated they will be
saved back to the table, as a new record, with a 'Section' identifier to
know its part of the initial section string.

This may be done between 0 and 20 times per form, where the user can select
'Add a Section'.

Building the SQL is simple but I am at a loss as to how to code this form?

Is it possible to keep adding a section to a form and how do I replicate the
fields and layout on each.

Suggestions appreciated.

Cheers
 
R

Rick Brandt

Kahuna said:
Hi Folks

I have a form used to select criteria which is then used to build an
SQL string.

The fields I already have in the form make up the selection for what
would be one line in a Query window (resolving into the AND portion
of the SQL string). Each of these fields relate to a table entry.

My challenge is to programmatically add another section to the form
with a replica of the fields in the first section - this will resolve
into the OR portion of the string. When these new fields are
populated they will be saved back to the table, as a new record, with
a 'Section' identifier to know its part of the initial section string.

This may be done between 0 and 20 times per form, where the user can
select 'Add a Section'.

Building the SQL is simple but I am at a loss as to how to code this
form?
Is it possible to keep adding a section to a form and how do I
replicate the fields and layout on each.

Suggestions appreciated.

Cheers

Have you looked at the Filter-By-Form functionality that is built into Access?
Does exactly what you are describing (including the automatic creation of "OR"
tabs).

If there is a reason you need to stay with a custom solution you need to create
all possible "OR" rows and then simply make them visible one at a time. Access
forms do not lend themselves to the generation of new controls during runtime.
 
S

strive4peace

Since the data structure will be the same in each section,
it sounds like you can use a continuous form and a form filter.

Each time you add a record, you can requery the form,
reapply the filter and voila! you have a new "section"

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
K

Kahuna

Thanks Crystal - that's what I was looking for. Excellent - I'll try it
tomorrow.

Cheers
 
S

strive4peace

You're welcome, Kahuna ;)

if you need more help, post back...

meanwhile, here is some code for you:

'add a new record
me.AddNew

'save record
if me.dirty then me.dirty = false

'set or remove filter
'where strFilter is your filter string
IF len(trim(strFilter) = 0 then
me.FilterOn = false
else
me.filter = strFilter
me.FilterOn = true
end if
me.requery

Requery will put record pointer back to the first one -- if
desired, you can save the record ID you are on and use
Bookmark to put it back after the Requery.


Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 

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