p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Access VBA (http://p2p.wrox.com/forumdisplay.php?f=80)
-   -   Adding records using form and subform (http://p2p.wrox.com/showthread.php?t=26376)

marcin2k March 3rd, 2005 04:30 PM

Adding records using form and subform
I need someone to get me started,
I have two tables:
   tCon: tTrans:
   ConID TransID
   EnvNo EnvNo
   Name Money

This is suppose to work like a bank account. I need to make a form with a subform so that I can type in an [EnvNo] in a textbox and in the subform it will display the [Name] and [Desc] for that EnvNo. That was the easy part because I got it to work the other part is that the main form has a textbox for [Money]. After a user types in an [EnvNo] and the information displays below in the subform, they can then type in the [Money] and press a commmand button. This is suppose to add a record to [tTrans] with the current [EnvNo] and that money. I got this to work but it only is able to add it once. If I was to press the command button again after adding one amount it just replaces the previous records money amount without adding a new record with a new transaction.

Please I need some help.

mmcdonal March 4th, 2005 12:53 PM

I have a few questions here about the structure of these tables, and how they are used in the forms.

I will assume this:

ConID - PK
EnvNo - FK (should go to TransID, not EnvNo, even if this is what is displayed)
Name - text
Desc - memo

TransID - PK
EnvNo - text or number
Money - Currency

If you create a form using AutoForm (for example) while on the tCon, or primary, table, then you have the tCon table data showing on the main form, and the tTrans table showing up in the subform.

1. Why is there a text box on the Main tCon form to enter tTrans.Money when that field is available on the subform already?

2. If you want to give the user the option to view the data in the subform in normal form view, why not have a button to switch between formview and datasheet view in the subform, rather than have data entry for the subform on the main form?

A more elegant way to do this if you want the data entry form to LOOK like the main form is to create a form on tTrans, and then create a query and subform to show the tCon data (locked) on the top of the tTrans form. You could even have the tTrans form show the complete tTrans data for that tCon account at each record.

For that matter you could also use the autoform wizard to creat the main form and subform - both in form view, then add a second subform showing the tTrans table in datasheet view below the first subform. As transactions are entered in the first normal subform, requery the second datasheet tTrans subform.

In any event, I wouldn't rely on an unbound text box and button to put data into a table when bound forms work more reliably.



mmcdonal March 4th, 2005 01:00 PM

Sorry, Make the main form on tTrans, but the observations are the same.


marcin2k March 7th, 2005 04:37 PM

Sorry for the late response, was away for a couple days.

My problem is that on the main form (tTrans) i don't have a textbox bound, I have a unbound textbox which I want the user to type a money amount and click save. And this saves to the record to tTrans. The EnvNo would be what is selected in the first textbox. I am able to add this to the record but I want it to be able to add two records if I pressed the command button twice. And Add new record did not work. Not sure if the subform is not letting me add more then one record until i leave the form.

All times are GMT -4. The time now is 03:36 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.