By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,495 Members | 1,076 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,495 IT Pros & Developers. It's quick & easy.

Setting Value of Combo Box on Subform

P: n/a
I have a main form called frmDemo with a subform frmStageTrack_Sub. On
the subform is a Combo Box CboTermID. The frmDemo is tied to tblDemo
and the frmStageTrack_Sub is tied to tblStageTrack. What I would like
to do is when a new record is created in frmDemo I would like to set
the CboTermID on the subform to a default value, say 1, without the
user having to set focus on the subform and selecting an item from the
combo box. Right now if the user does not select a TermID on the
subform no record is created in the StageTrack table when a new record
is created in frmDemo. I only wish to set a default value if the
TermID is Null.
I have tried the following in the AfterUpdate event of frmDemo

Private Sub Form_AfterUpdate()
If IsNull(Me.Forms.frmDemo.frmStageTrack_Sub.Form.Cbo TermID) Then
Forms.frmDemo.fromStageTrack_Sub.CboTermID = 1
End If

End Sub

But I keep getting a runtime error. What is the correct way to set the
CboTermID from the Main form?

May 3 '06 #1
Share this Question
Share on Google+
6 Replies


ADezii
Expert 5K+
P: 8,597
I have a main form called frmDemo with a subform frmStageTrack_Sub. On
the subform is a Combo Box CboTermID. The frmDemo is tied to tblDemo
and the frmStageTrack_Sub is tied to tblStageTrack. What I would like
to do is when a new record is created in frmDemo I would like to set
the CboTermID on the subform to a default value, say 1, without the
user having to set focus on the subform and selecting an item from the
combo box. Right now if the user does not select a TermID on the
subform no record is created in the StageTrack table when a new record
is created in frmDemo. I only wish to set a default value if the
TermID is Null.
I have tried the following in the AfterUpdate event of frmDemo

Private Sub Form_AfterUpdate()
If IsNull(Me.Forms.frmDemo.frmStageTrack_Sub.Form.Cbo TermID) Then
Forms.frmDemo.fromStageTrack_Sub.CboTermID = 1
End If

End Sub

But I keep getting a runtime error. What is the correct way to set the
CboTermID from the Main form?
'The correct Syntax for setting the value of a Control on a Sub-Form from
'the Parent Form is as follows:


Forms![ParentFormName]![SubFormName].Form![SubFormField] = ????
May 3 '06 #2

P: n/a
Read this article... there's an example there that should sort this
out...

http://www.mvps.org/access/forms/frm0031.htm

May 3 '06 #3

P: n/a
Thanks for the help. Following works great.

If IsNull(Forms!MainForm!Subform1.Form!ControlName) Then
'Me!Subform1.Form!Subform2.Form!ControlName = 1
End If

OR
If IsNull(Forms!frmDemo!frmStageTrack_Sub.Form!TermID ) Then
Me!frmStageTrack_Sub.Form!TermID = 1
End If

I was wondering if anyone had an opinion on a better way of setting the
TermID

May 3 '06 #4

P: n/a
Sorry, the first part should have read

If IsNull(Forms!MainForm!Subform1.Form!ControlName) Then
'Me!Subform1.Form!ControlName = 1
End If

May 3 '06 #5

P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Reference a subform from the current form:

Me!frmStageTrack_sub!CboTermID
or
Me!frmStageTrack_sub.Form!CboTermID

Why don't you just set the ComboBox's Default property to 1? If the
ComboBox is a bound control, setting its Value property to 1 means you
are creating a new record in the subform - are all the required fields
getting the values they need?
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRFkMP4echKqOuFEgEQLRZwCg+sMvPH2FI2p61CRUudSEaq TkPj4AoMK2
7L9y9L7TaA2oSb0XDpEj0uRr
=FrAT
-----END PGP SIGNATURE-----
Rick wrote:
I have a main form called frmDemo with a subform frmStageTrack_Sub. On
the subform is a Combo Box CboTermID. The frmDemo is tied to tblDemo
and the frmStageTrack_Sub is tied to tblStageTrack. What I would like
to do is when a new record is created in frmDemo I would like to set
the CboTermID on the subform to a default value, say 1, without the
user having to set focus on the subform and selecting an item from the
combo box. Right now if the user does not select a TermID on the
subform no record is created in the StageTrack table when a new record
is created in frmDemo. I only wish to set a default value if the
TermID is Null.
I have tried the following in the AfterUpdate event of frmDemo

Private Sub Form_AfterUpdate()
If IsNull(Me.Forms.frmDemo.frmStageTrack_Sub.Form.Cbo TermID) Then
Forms.frmDemo.fromStageTrack_Sub.CboTermID = 1
End If

End Sub

But I keep getting a runtime error. What is the correct way to set the
CboTermID from the Main form?

May 3 '06 #6

P: n/a
I tried setting the default value on the combo box but it does not
create a record in the table unless I physically put focus on the
subform and change something.

May 4 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.