473,796 Members | 2,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Setting Value of Combo Box on Subform

I have a main form called frmDemo with a subform frmStageTrack_S ub. On
the subform is a Combo Box CboTermID. The frmDemo is tied to tblDemo
and the frmStageTrack_S ub 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_AfterUpdat e()
If IsNull(Me.Forms .frmDemo.frmSta geTrack_Sub.For m.CboTermID) Then
Forms.frmDemo.f romStageTrack_S ub.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 7494
ADezii
8,834 Recognized Expert Expert
I have a main form called frmDemo with a subform frmStageTrack_S ub. On
the subform is a Combo Box CboTermID. The frmDemo is tied to tblDemo
and the frmStageTrack_S ub 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_AfterUpdat e()
If IsNull(Me.Forms .frmDemo.frmSta geTrack_Sub.For m.CboTermID) Then
Forms.frmDemo.f romStageTrack_S ub.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!Ma inForm!Subform1 .Form!ControlNa me) Then
'Me!Subform1.Fo rm!Subform2.For m!ControlName = 1
End If

OR
If IsNull(Forms!fr mDemo!frmStageT rack_Sub.Form!T ermID) Then
Me!frmStageTrac k_Sub.Form!Term ID = 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!Ma inForm!Subform1 .Form!ControlNa me) Then
'Me!Subform1.Fo rm!ControlName = 1
End If

May 3 '06 #5
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Reference a subform from the current form:

Me!frmStageTrac k_sub!CboTermID
or
Me!frmStageTrac k_sub.Form!CboT ermID

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:::mgf0 0 <at> earthlink <decimal-point> net
Oakland, CA (USA)

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

iQA/AwUBRFkMP4echKq OuFEgEQLRZwCg+s MvPH2FI2p61CRUu dSEaqTkPj4AoMK2
7L9y9L7TaA2oSb0 XDpEj0uRr
=FrAT
-----END PGP SIGNATURE-----
Rick wrote:
I have a main form called frmDemo with a subform frmStageTrack_S ub. On
the subform is a Combo Box CboTermID. The frmDemo is tied to tblDemo
and the frmStageTrack_S ub 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_AfterUpdat e()
If IsNull(Me.Forms .frmDemo.frmSta geTrack_Sub.For m.CboTermID) Then
Forms.frmDemo.f romStageTrack_S ub.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
8238
by: Terry Bickle | last post by:
Please forgive me for using the wrong term here or there. I'm an old Excel 4 macro guy who didn't convert to VB and I'm tinkering with an Access 2000 DB. I'm sure there is a simple Access 101 answer for this. I have a subform which the user selects an item description from a combo box from a table. I want to obtain the cost for the item (another field in the table) also. I've been able to produce the second data field by rewriting the...
2
2123
by: CSDunn | last post by:
Hello, I have a field called 'TestGrade'in a subform called 'frmSelectByTestSub'that I need to assign a default value to, and the value needs to be an integer value that is exactly the same as the value in a field called 'Grade' that is also in the subform. The name of the main form is 'frmSelectByTest'. The 'SourceObject' of the subform and the subform name are the same. 'Grade' in the subform can be different for each student record...
0
1122
by: CSDunn | last post by:
Hello, I have a subform where the 'Name' and 'Source Object' properties are both 'frmSelectByTestSUB'. This subform resides in a main form called 'frmSelectByTest'. In the subform, I have a combo box currently named 'Combo6' that displays a list of student names. I need to set up functionality so that after the name in the combo box is selected (After Update?), a textbox that is bound to a field called 'TestGrade' will have its value...
0
1267
by: CSDunn | last post by:
Hello, I have a subform where the 'Name' and 'Source Object' properties are both 'frmSelectByTestSUB'. This subform resides in a main form called 'frmSelectByTest'. In the subform, I have a combo box currently named 'Combo6' that displays a list of student names. I need to set up functionality so that after the name in the combo box is selected (After Update?), a textbox that is bound to a field called 'TestGrade' will have its value...
1
8522
by: John Michael | last post by:
I have a form that has a subform that has a subform. The subform loads a record based on a combo lookup box in the main form. I'm trying to set a value in the subform based on a value in a subform of the subform. the main Form is called Subform is called Subform in the subform is called
4
1994
by: elfyn | last post by:
I'm currently developing a Fleet system which enables the user to enter Parts used to Service a vehicle. The parts are available through a Combo Box on a form and if the user enters a new Part the systems checks the NoinList and then opens a new Form where the user can enter the new Part Details i.e. price, VAT Rate, Supplier etc. What I'd like is for the value entered in the Combo box for the new part e.g. Fuel Filter, to appear in the...
1
2970
by: BigJay | last post by:
I am 1. trying to have a combobox used as a selector to display records in a subform. and not sure on how to get selected info into subform.the combo is populated but can not get subform updated when selection is made..... 2. I also want to use one combo box to select a second set of criteria in a second combo box that is then used to refine displayrd records in a a subform.... am afraid im lost on this..??? I have a main table that...
6
3684
by: Dave | last post by:
I want to put the information that the user selects in my combo boxes into a subform that lies on the same form as the combo boxes. Thanks for your help already, Dave
5
2234
by: MNNovice | last post by:
My combo box is pulling data from tblAccounts using its PK (auto number) AccountID but displaying AccountNo (text). Is it possible to set the default value for this combo box to one of the AccountNos? Let me explain AccountID = 1 AccountNo = 4xxxx I would like cboAccount which is a combo box on a subform (sfrmGrantBudget) to display "xxxxx" as a default value. Is it possible? When I tried, it displays the AccountID for AccountNo...
0
9533
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10461
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10239
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9057
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7555
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6796
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.