Entering Data from a sub-form : Access 97 (1 Viewer)

Paulp

New member
Local time
Today, 14:43
Joined
Dec 6, 1999
Messages
5
I set up a sub-form with a single field (user name) so that the current user did not need to enter his/her name with each record (they could select it with the first record and it would then remain in the box until another user changed it). My problem is the user name is not being posted to the table with the rest of the fields from the main form. Is there something that I need to do so that the data from my sub-form gets entered into the table along with the fields on the main form?
 

Clarence

Registered User.
Local time
Today, 14:43
Joined
Oct 3, 1999
Messages
14
First of all make sure that your sub form is NOT linked to the main form on either the Child or Master (This is done the DATA section of the subform displayed on your master form).
Next : Using a subform name of 'mySfrm'
Main form control = txtUserName
sub form control name = txtsfUserName

In your main forms ON CURRENT event
put the following code

Me.txtUserName = me.mySfrm.form.txtsfUserName

This will pick up the value contained in control 'txtsfUsername' from the sub form and assign it to control txtUserName on the main form.

You may need to do a me.refresh to complete this operation.

An alternative to this is to use the currentuser function, use the oncuurent event with

me.txtUserName = currentuser()

this will work if you allways want to use the currently logged on user name, it has the benefit of not requireing a sub form and does not carry the system overhead of using a sub form.

The 3rd alternative, and the on I prefer to use due to its flexibility, is to use a opened, non-visible form. This form can be opened a start up and any values you want to put in it, then made invisible. After this you can reference any values on the visible form any time you want to. This is very useful for holding any system preferences, dates or other paramters. using code you can simple make the form visible at any time you want to alter any of the parameters.
Hope this helps
 

Users who are viewing this thread

Top Bottom