New record

S

swas

Hi,
I have a main form with a treeview control, and several subforms on a tab
control. Depending on the treeview node determines the recordsource for the
appropriate subform, and whether it is editable or not. I am controlling the
recordsource to restrict the recordset to a single record to keep network
traffic to a minimum. All this is working fine.

When I want to add a new record, I want to allow this only when a certain
tree level is selected for a given subform, which detecting and controlling
this is fine also. My problem is how to manage the subform fields for a new
record. If I set it to a new record automatically when the appropriate tree
node is selected it means new records can inadvertantly be added without
realising. Because it is a bound form I can't just set the recordsource to
nothing until an 'add' button is pressed as all bound fields show '#Name'
which looks bad. If it is a new record I can't set 'allowedits' to false. I
can't set subform.visible = false as I can't have the 'add' button!

Any approach I am trying seems to solve one problem but create another. The
last way which I haven't tried is to set all controls .visible to false
except the 'add' button, then I can control when I actually go to the new
record.

I know this is a verbose question and I hope I have explained it clearly. I
have spent more than a day buggering around with different options but can't
get a simple, elegant solution. Any ideas?

Thanks in advance.

swas




As best I can see I
 
T

TonyT

Why not trap the *accidental* records with the forms before update event and
cancel it if required?

TonyT..
 
S

swas

Tony,

Thanks for the response. I tried trapping the form keypress event and
setting to 0 until the 'Add' button has been pressed, which seems to work
fine. To be sure I don't get unwanted empty records I am also using me.undo
on form lostfocus, but I'm not sure if this is redundant.

I thought about the beforeupdate event but felt it was leaving user messages
until after they have entered data, rather than preventing before they start,
but is not a bad option.

Once you move outside straight bound Jet forms coding seems to exponentially
grow. I was initially considering an ADP / SQL Server setup which would be
even more involved... especially self teaching.

Thanks for the response.

swas
 
T

TonyT

I think you'll find the Lost_Focus event is too late on leaving the subform
as the record will already have been saved by then if it's going to be, so
yes it seems redundant.

My approach would be to leave the subform unbound and then create the
recordsource once the 'add' button has been pressed, rather than just when
the appropriate tree level has been reached, provided you can cross reference
to the tree level at that point in time.

TonyT..
 
S

swas

Tony,

Yes you are right - that should be beforeupdate not lostfocus... but I need
to do some exploring as to whether empty records can appear regardless - I
have a primary key field that needs entering and validated correct / unique
so assuming this has been accepted it would be reasonable to assume the
record is an intended one.

If I leave the form unbound (By which I assume to mean no recordsource set)
then all bound controls display '#Name' which looks tacky.

Thanks for the thoughts.

swas
 
T

TonyT

thinking around the problem, you could have the subform as is for initial
viewing purposes and then have the 'add' button opening another pop-up form
entirely for adding new records - you could position to appear directly over
the subform if you so wished.

TonyT..
 

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