Connecting Tech Pros Worldwide Forums | Help | Site Map

Setting Value of Combo Box on Subform

Rick
Guest
 
Posts: n/a
#1: May 3 '06
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?


ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,219
#2: May 3 '06

re: Setting Value of Combo Box on Subform


Quote:

Originally Posted by Rick

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] = ????
pietlinden@hotmail.com
Guest
 
Posts: n/a
#3: May 3 '06

re: Setting Value of Combo Box on Subform


Read this article... there's an example there that should sort this
out...

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

Rick
Guest
 
Posts: n/a
#4: May 3 '06

re: Setting Value of Combo Box on Subform


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

Rick
Guest
 
Posts: n/a
#5: May 3 '06

re: Setting Value of Combo Box on Subform


Sorry, the first part should have read

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

MGFoster
Guest
 
Posts: n/a
#6: May 3 '06

re: Setting Value of Combo Box on Subform


-----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:[color=blue]
> 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?
>[/color]
Rick
Guest
 
Posts: n/a
#7: May 4 '06

re: Setting Value of Combo Box on Subform


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.

Closed Thread