Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 3rd, 2005, 04:30 PM
Authorized User
 
Join Date: Jan 2005
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
   Desc

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.

 
Old March 4th, 2005, 12:53 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

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

I will assume this:

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

tTrans:
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.

Question:
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.

HTH



mmcdonal
 
Old March 4th, 2005, 01:00 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

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

mmcdonal
 
Old March 7th, 2005, 04:37 PM
Authorized User
 
Join Date: Jan 2005
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Subform not displaying values after adding updates jlangdon Access 1 April 23rd, 2008 03:00 PM
Autopopulate Subform with New Records Odeh Naber Access 0 August 2nd, 2007 04:29 AM
filtering records on subform from an unbound combo jd_erd Access 3 February 12th, 2007 11:21 PM
Looping through subform records V Access VBA 8 April 20th, 2004 08:10 AM
records in subform stoneman Access 1 October 27th, 2003 11:46 AM





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