Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 6th, 2004, 05:19 PM
Authorized User
 
Join Date: Nov 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Required field dependent on another field...

I am trying to make a form field required only if a selection is made on a separate combo box. i.e. A form collects data for insurance quotations. Each record (quotation entered on form) can hold up to 5 coverages (life, disability, medical, accident or pension). If you, for example, choose "Life" for coverage 1, I want the status (pending, sold or lost) field to become required.

I wrote the following code, which incidentally does not work. Can anyone point me in the right direction? I also put this code in the BeforeUpdate event; is this correct?
________
Dim type1 As Field
Dim status1 As Field

type1 = tblQuoteLookup.cboCover1
status1 = tblQuoteLookup.cboCover1Status

If Not IsNull(type1) Then
status1.Required
End If
________

Many thanks,
Nick
 
Old January 7th, 2004, 08:57 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Why not put an After Update event on the combo box so that if "Life" is chosen, you get a message to enter the status, enable the status field, and then give the status field the focus? Otherwise, keep the status field disabled. Upon the form's On Close event, if status is null then give an error message and prevent the form from closing and give status the focus again.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old January 7th, 2004, 11:21 AM
Authorized User
 
Join Date: Nov 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Greg!

I did not use your solution, but it inspired me to devise the following:
_______
Private Sub chkC1_Click()

cover1.Enabled = chkC1
comment1.Enabled = chkC1
premium1.Enabled = chkC1
status1.Enabled = chkC1

If chkC1 = True Then
status1 = "Pending"
End If

End Sub
_______
I placed a check box next to each 'cover'. When the check box is true, all the fields for that coverage (Life, or whatever it may be) become enabled and the required 'status' field is filled with the default value "Pending".

Thanks again,
Nick
 
Old January 14th, 2004, 10:37 AM
Authorized User
 
Join Date: Nov 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I made a small change to this code. If the status is 'sold' for example, and I check the corresponding check box, it changes from 'sold' to 'pending' again. So...

If IsNull(status1) And chkC1 = True Then





Similar Threads
Thread Thread Starter Forum Replies Last Post
required field validator rocksbhavesh ASP.NET 1.0 and 1.1 Basics 2 June 30th, 2007 03:20 AM
Custmization in Required Field validator shivendra012 ASP.NET 1.0 and 1.1 Professional 1 April 19th, 2007 05:14 AM
Required Field Validator RGB ASP.NET 1.0 and 1.1 Basics 3 March 31st, 2006 03:31 PM
required field valuator melvik ASP.NET 1.0 and 1.1 Professional 2 August 24th, 2003 05:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.