Default Text Value Depending on Selection

S

srpatel

Hello

I have a form which has several text boxes and about four combo boxes.
What i need to implement is when a user selects a field from the combo
box e.g. cboItem > Blue, I need certain text boxes to default to the
word NA. Is that possible?

I think i have to implement the code in the after update event
procedure but do not know how to.

Any help would be great!

Thanks
Shreekant
 
S

strive4peace

yes, you can use the control's AfterUpdate event

'~~~~~~~~~~~
select case me.activecontrol

case "blue"
me.controlname1 = "NA"
me.controlname2 = "NA"
me.controlname3 = "NA"

case "red"
'statements

case else
'statements

end select
'~~~~~~~~~~~

AfterUpdate will run anytime you change the field -- if you
just want to limit this to records that are being added,
insert this line at the top

'~~~~~~~~~~~
if not me.newrecord then exit sub
'~~~~~~~~~~~

alternately, you can use the AfterInsert event if you just
want it to run for new records.

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
S

srpatel

Hi Crystal,

Thank you for your earlier post. I think I should have given you more
information.

I have two requirements,

1. When an item is selected from the cboEllipseAssetType, certain text
boxes have to be greyed out so that users cannot enter any data.

2. From the same combo box, cboEllipseAssetType, I also require what I
mentioned above that certain text boxes should default to NA.

This is the current code I have implemented on the after update for the
text boxes to be greyed out.

Private Sub cboEllipseAssetType_AfterUpdate()
Select Case Me.cboEllipseAssetType
Case "Access Gantry"
Me![cboRoomCodeDescription].Enabled = False
Me![chkBoundaryWall].Enabled = False
Me![txtHeadroom(Signed)].Enabled = False
Me![txtDepth].Enabled = False
Me![txtDiameter].Enabled = False
Case Else
Me![cboRoomCodeDescription].Enabled = True
Me![chkBoundaryWall].Enabled = True
Me![txtHeadroom(Signed)].Enabled = True
Me![txtDepth].Enabled = True
Me![txtDiameter].Enabled = True
End Select
End Sub

I tried implemented your method on top of this but I was not very
successful.

I apologise for not being very informative on my initial post. I would
appreciate your further help possible.

Thanks
Shreekant
Keen Access Developer!
 
S

strive4peace

Hi Shreekant,

It seems you already have the basic framework you need. How
about something like this:

'~~~~~~~~~~~~~~~~~~~~~~

Private Sub cboEllipseAssetType_AfterUpdate()

dim mBoo as boolean

Select Case Me.cboEllipseAssetType
Case "Access Gantry"
mBoo = False

Me
'you will need to finish the above line
'after you paste, type a period after Me
'so you are prompted with the controlnames
'put statement in this form:
'me.controlname = Null

Case Else
mBoo = true
End Select

Me.cboRoomCodeDescription.Enabled = mBoo
Me.chkBoundaryWall.Enabled = mBoo

'you should not use ( ) in your names
'Me.txtHeadroom(Signed).Enabled = mBoo
'rename you control
Me.txtHeadroom_Signed.Enabled = mBoo

Me.txtDepth.Enabled = mBoo
Me.txtDiameter.Enabled = mBoo

End Sub

'~~~~~~~~~~~~~~~~~~~~~~

it is better to use Me. than Me! while you are coding so
that you can be prompted with acceptable choices. Try using
this when you code -- perhaps you are not using the correct
controlnames.

'~~~~~~~~~~~~~~~~~~~~~~

You should have an AssetTypes table that looks something
like this:

*AssetTypes*
ATypeID, autonumber
AssetType, text

In related tables, you chould have

ATypeID, long integer, defaultValue =Null
(set default value if not all records will be filled out so
that you can enforce referential integrity)

do NOT make this a lookup control in the table design --
that is done in forms with comboboxes

'~~~~~~~~~~~~~~~~~~~~~~

on your form, here is an example with the properties you
need to set for a combobox that stored the ID and displays
the text

combobox control

Name --> ATypeID
ControlSource --> ATypeID
RowSource -->
SELECT ATypeID, AssetType
FROM AssetTypes
ORDER BY AssetType

BoundColumn --> 1
ColumnCount --> 2

columnWidths --> 0;2
(etc for however many columns you have
-- the ID column will be hidden since its width is zero)

ListWidth --> 2
(should add up to the sum of the column widths)

ATypeID will be stored in the form RecordSource while
showing you information from another table...

'~~~~~~~~~~~~~~~~~~~~~~

In the code, you will test the numeric ATypeID, not the text
AssetType value.

'~~~~~~~~~~~~~~~~~~~~~~

If Ellipse was a descrptive for AssetType, add another field
to the AssetTypes table with category. If you have repeated
categories, you may need a Categories table with CatID.



Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
Hi Crystal,

Thank you for your earlier post. I think I should have given you more
information.

I have two requirements,

1. When an item is selected from the cboEllipseAssetType, certain text
boxes have to be greyed out so that users cannot enter any data.

2. From the same combo box, cboEllipseAssetType, I also require what I
mentioned above that certain text boxes should default to NA.

This is the current code I have implemented on the after update for the
text boxes to be greyed out.

Private Sub cboEllipseAssetType_AfterUpdate()
Select Case Me.cboEllipseAssetType
Case "Access Gantry"
Me![cboRoomCodeDescription].Enabled = False
Me![chkBoundaryWall].Enabled = False
Me![txtHeadroom(Signed)].Enabled = False
Me![txtDepth].Enabled = False
Me![txtDiameter].Enabled = False
Case Else
Me![cboRoomCodeDescription].Enabled = True
Me![chkBoundaryWall].Enabled = True
Me![txtHeadroom(Signed)].Enabled = True
Me![txtDepth].Enabled = True
Me![txtDiameter].Enabled = True
End Select
End Sub

I tried implemented your method on top of this but I was not very
successful.

I apologise for not being very informative on my initial post. I would
appreciate your further help possible.

Thanks
Shreekant
Keen Access Developer!
 
S

srpatel

Hi Crystal,

Thanks for your help. I have implemented my code using your method and
it works.

I have changed my control names as well. I have got my tables for the
assets but I still cannot work out how to have certain text boxes
default to NA when a selection is made from the cboElipseAssetType.

Could you possibly explain this to me in further detail?

Thanks
Shreekant
Keen Access Developer!
 
S

srpatel

Hi Crystal,

I have yet encountred another problem.

When a user select a case "Asset Gantry" from the combo box,
cboEllipseAssetType, the relevant text boxes do get greyed out.

The problem I have is the updating of the text boxes. For example I was
simply testing out the form and noticed that when I clicked Access
Gantry the text boxes/cbo's greyed out. As I selected another case
such as Access Ladder, its relevant text boxes/cbo's greyed out, BUT
when I selected the Access Gantry case again, all the text boxes/cbo's
remained greyed, they did not un-change to the ones specific to Access
Gantry.

Do I need an before update aswell? Where am I going wrong?

Many Thanks
Shreekant

This is part of the current code implemented!

Private Sub cboEllipseAssetType_AfterUpdate()
Dim mBoo As Boolean

Select Case Me.cboEllipseAssetType
Case "Access Gantry"
mBoo = False
Me.cboRoomCodeDesc.Enabled = mBoo
Me.txtBuildingNumber.Enabled = mBoo
Me.chkBoundaryWall.Enabled = mBoo
Me.txtBusRoute.Enabled = mBoo
Me.txtHeadroomActual.Enabled = mBoo
Me.txtHeadroomSigned.Enabled = mBoo
Me.txtDepth.Enabled = mBoo
Me.txtDiameter.Enabled = mBoo
Me.txtNumberofArches.Enabled = mBoo
Me.txtNumberofSpans.Enabled = mBoo
Me.txtObstacleCrossed.Enabled = mBoo
Me.txtRoadCarryName.Enabled = mBoo
Me.chkSafetyCriticalAsset.Enabled = mBoo
Me.txtSkewSpan.Enabled = mBoo
Me.txtSquareSpan.Enabled = mBoo
Me.txtBoundaryDemarcation.Enabled = mBoo

Case "Access Ladder"
mBoo = False
Me.cboRoomCodeDesc.Enabled = mBoo
Me.txtOffset.Enabled = mBoo
Me.txtContAssetSegmentStartM.Enabled = mBoo
Me.txtContAssetSegmentEndM.Enabled = mBoo
Me.txtBuildingNumber.Enabled = mBoo
Me.txtRoomNumber.Enabled = mBoo
Me.chkBoundaryWall.Enabled = mBoo
Me.txtBusRoute.Enabled = mBoo
Me.txtConstructionYear.Enabled = mBoo
Me.txtDateofCommissioning.Enabled = mBoo
Me.txtDutyLoading.Enabled = mBoo
Me.txtExpectedLifeExpiryDate.Enabled = mBo
Me.txtHeadroomActual.Enabled = mBoo
Me.txtHeadroomSigned.Enabled = mBoo
Me.txtLength.Enabled = mBoo
Me.txtHeight.Enabled = mBoo
Me.txtWidth.Enabled = mBoo
Me.txtDepth.Enabled = mBoo
Me.txtDiameter.Enabled = mBoo
Me.txtNominalServiceLife.Enabled = mBoo
Me.txtNumberofArches.Enabled = mBoo
Me.txtNumberofSpans.Enabled = mBoo
Me.txtObstacleCrossed.Enabled = mBoo
Me.cboParapettype.Enabled = mBoo
Me.txtRoadCarryName.Enabled = mBoo
Me.chkSafetyCriticalAsset.Enabled = mBoo
Me.txtSkewSpan.Enabled = mBoo
Me.txtSquareSpan.Enabled = mBoo
Me.cboStrutsAnchorsTies.Enabled = mBoo
Me.txtAssetCapacity.Enabled = mBoo
Me.txtBoundaryDemarcation.Enabled = mBoo
Case Else
mBoo = True

End Select
End Sub
 
S

strive4peace

You are missing the point of using the variable, mBoo (boolean)

You should save yourself statements that are common -- set
mBoo according to your case value and then put statements
like this

Me.cboRoomCodeDesc.Enabled = mBoo

AFTER End Select

Now that I see your controls, I suspect there is a deeper
problem -- as a general rule, you should use one form or
subform for data entry into each table. It looks like you
are entering data into several tables (or what should be
several tables) with one form.


What is your table and field structure?

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
S

srpatel

Ok the Table and field Structure that is currently implemented:


Tables:

tblAssetsB&S
AssetID PK AutoNumber
UniqueID TextIndexedNODuplicates
LineID Text,Lookup,
Location Lookup
Asset_NumberID Lookup
EllipseAssetType Text, but I have placed a Row source in the properties to lookup.
RoomCodeDesc text, Lookup
Offset text, Lookup
ContAssetSegntStartM Num
ContAssetSegntEndM Num
BuildingNumber Num
RoomNumber Num
BoundaryWall Yes/No
BusRoute text
ConstructionYear Date
DateofCommissioning date
DutyLoading Num
ExpectedLifeExpiryDate Date
HeadroomActual Num
HeadroomSigned Num
Length Num
Height Num
Width Num
Depth Num
Diameter num
NominalServiceLife num
NumberofArches num
NumberofSpans num
ObstacleCrossed text
Parapettype text Lookup
RoadCarryName text
SafetyCriticalAsset Yes/No
SkewSpan num
SquareSpan num
StrutsAnchorsTies num
AssetCapacity num
BoundaryDemarcation text
tblAsset_Numbers

Asset_NumberID PK AutoNumber
Asset_Number text ( as it contains words and numbers. several assetNumbers which are for each line and each asset number has a unique id)
tblUniqueID

ID AutoNumber
Unique Id PK text ( several unique id for each line)
LineID Lookup, Number
Asset_NumberID Lookup, Number


tblEllipseAssetType
Ellipse Asset ID PK AutoNumber
Ellipse Asset Type Text ( 55 records)
tblLine

LineID PK AutoNumber
Line Text (11 records)

My relationships seem to work as I can see them relate within the
tables and the form.

Right my form;

I have one form which is bound to the tblAssetsB&S, The form has all
those fields as they have to be filled. IN ELLIPSEASSETTYPE, depending
on the selection made, more than 4 of those text boxes/checkboxes/combo
boxes have to be either greyed out, default to NA or IN.

So example:

cboEllipseAssetType:
- Access Gantry
- Foot Bridge
- Pipe Bridge

I select Access Gantry and fields - Construction year default to NA,
Duty Loading defaults to CIL, BusRoute= Greyed out, HeadroomActual =
grey out, and HeadroomSigned = greyed out

Then when say foot Bridge is selected, other fields get greyed out or
less get greyed depending on the requirements.

I have not used any subforms as I am very new to access development.
Your help with this database design would be much appreciated.

Many Thanks
Shreekant
Keen Access Developer!
 
S

strive4peace

Hi Shreekant,

Don't use lookup fields in table design
http://www.mvps.org/access/lookupfields.htm

limit the use of lookups to comboboxes and listboxes on forms

Parapettype should be an ID field (long integer) that
corresponds to the Primary Key field in the other table,
which should be an autonumber.


Consider the length of your data when you assign fieldnames

DateofCommissioning is 19 characters, a date is 8 characers
.... consider a shorter name like DateCommis

Likewise, SafetyCriticalAsset, is WAAAY long for a short
Yes/No field... fieldnames can be more cryptic (SafCritAsset
is still a bit long for the data) -- fill out field
descriptions -- this is what will be used for the statusbar
text when the forms are created.

Don't use spaces in fieldnames

Ellipse Asset ID --> EllAsID

Don't use "ID" in any fieldname that is not a long integer
-- if you have "ID" text fields, use "Code" or "Num" ... ie:

Unique Id --> UniqCode

Don't use special characters in names

tblAssetsB&S --> tbl_Assets_B_S

I also suspect this table should actually be broken down
into multiple tables but since I do not know what each piece
of data refers to, I can't tell which fields to move.

Here is a link that describes the basics of forms and subforms

http://www.techiwarehouse.com/cms/engine.php?page_id=31e49405#3



Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
S

srpatel

Hello Crystal,

Thank you for the detailed information. I will have aread on it and
look into changing my database design.

Regards
Shreekant
 
S

strive4peace

you're welcome, Shreekant ;) happy to help

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top