Acess97 Syntax to set the value of a field in a subform dataSheet

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am attempting to use the subform's 'Form_BeforeInsert' event to trigger code
The BeforeInsert event appears to be a safe place to set values, in a new
record, without triggering other events…

Fact Pattern:
Who makes each call needs to be included in each record added to the table.
The application requires the user to enter their ID at strart up. This ID is
stored in a variable Dim ensioned in a module named 'GlobalMod' as

'Public strCallerName As String' .

The Parent form's name is 'CallList'
The SubFormControl name is 'CallsSubform'
The Source Object is ' CallsSubform'
The Subform's name is CallsSubForm


QUESTIONS:
1) Will code in a Form work the same when it is running as a SubForm?
2) What is the syntax when I want to set the value of the Table.Field
named 'CalledBy', which is attached to a textBox named 'txtCalledBy' in the
subform which is in the DataSheet mode?
i.e. : If the subForm was NOT a DataSheet I could say:

TxtCalledBy.Text = strCallerName

to insert the users ID into the tenth field of the datasheet. (with 1 being
the first field in the table with a total of 10 fields)

Thanks for you help
 
Marvin said:
I am attempting to use the subform's 'Form_BeforeInsert' event to trigger code
The BeforeInsert event appears to be a safe place to set values, in a new
record, without triggering other events…

Fact Pattern:
Who makes each call needs to be included in each record added to the table.
The application requires the user to enter their ID at strart up. This ID is
stored in a variable Dim ensioned in a module named 'GlobalMod' as

'Public strCallerName As String' .

The Parent form's name is 'CallList'
The SubFormControl name is 'CallsSubform'
The Source Object is ' CallsSubform'
The Subform's name is CallsSubForm


QUESTIONS:
1) Will code in a Form work the same when it is running as a SubForm?
2) What is the syntax when I want to set the value of the Table.Field
named 'CalledBy', which is attached to a textBox named 'txtCalledBy' in the
subform which is in the DataSheet mode?
i.e. : If the subForm was NOT a DataSheet I could say:

TxtCalledBy.Text = strCallerName

to insert the users ID into the tenth field of the datasheet. (with 1 being
the first field in the table with a total of 10 fields)


It doesn't matter how the form/subform are diaplayed. You
would use the same code.

What does matter is where the code is executing. If the
code is in the main form, you use this to set a subform's
text box:
Me.CallsSubform.Form.txtCalledBy = strCallerName
If the code is in the subform, then use:
Me.txtCalledBy = strCallerName

Note that you do **not** use the Text property to assign a
control's value.
 
Simple additional advice.

Global variables are nice, but they can reset to a vzero-length string,
zero, etc. This will happen if you have any unhandled errors occur when the
database is running. So when I use global variables I don't rely on them
existing for long stretches of time.

Personnally, I find it better to use a control on a form to store the
value - usually I have a hidden "logon" form that can hold the values in
textbox controls. An alternative is to assign the value to a custom
property.
 
John Spencer said:
Simple additional advice.

Global variables are nice, but they can reset to a vzero-length string,
zero, etc. This will happen if you have any unhandled errors occur when the
database is running. So when I use global variables I don't rely on them
existing for long stretches of time.

Personnally, I find it better to use a control on a form to store the
value - usually I have a hidden "logon" form that can hold the values in
textbox controls. An alternative is to assign the value to a custom
property.
 
Back
Top