469,644 Members | 1,959 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,644 developers. It's quick & easy.

Setting Value of Combo Box on Subform

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
6 7039
ADezii
8,800 Expert 8TB
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
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
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
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
-----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
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.

Similar topics

2 posts views Thread by CSDunn | last post: by
reply views Thread by CSDunn | last post: by
reply views Thread by CSDunn | last post: by
1 post views Thread by John Michael | last post: by
4 posts views Thread by elfyn | last post: by
1 post views Thread by BigJay | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.