disable text box via combo box

G

Guest

i have a form designed as an invoice, i have a combo box which is linked to a
table where i get values like "waiting Payment", "closed" etc. When i select
"closed" i want all my text boxes and combo boxes on my form to be diabled.
Any ideas???
 
G

Guest

Hi, StuJol.

I'll assume that you want to keep the original combo box Enabled so that you
could theoretically change it back. Loop through the controls, and disable
all textboxes and combo boxes:

Dim ctl as Control

If Me![YourStatusComboBox] = "Closed" Then

For Each ctl In Me.Controls
If ctl.Name<> "YourStatusComboBoxName" Then
If (ctl.ControlType = acTextbox OR ctl.ControlType =
acComboBox) Then
ctl.Enabled = False
End If
End If
Next ctl

End If

Alternatively, you can use the Tag property to flag the ones you'd like to
keep open. Enter some text such as "KeepOpen", and modify the test
accordingly:

If ctl.Tag <> "KeepOpen" Then ...

Also, if the bound column of your combo box is a numeric type, even though
it displays "Closed", its value might be 1,2, etc., so the test would be
something like:

If Me![YourStatusComboBox] = 1

Hope that helps.
Sprinks
 
G

Guest

Could you please try and explain in more simple terms as im a beginner and
are finding it difficult to understand your response

many thanks

Sprinks said:
Hi, StuJol.

I'll assume that you want to keep the original combo box Enabled so that you
could theoretically change it back. Loop through the controls, and disable
all textboxes and combo boxes:

Dim ctl as Control

If Me![YourStatusComboBox] = "Closed" Then

For Each ctl In Me.Controls
If ctl.Name<> "YourStatusComboBoxName" Then
If (ctl.ControlType = acTextbox OR ctl.ControlType =
acComboBox) Then
ctl.Enabled = False
End If
End If
Next ctl

End If

Alternatively, you can use the Tag property to flag the ones you'd like to
keep open. Enter some text such as "KeepOpen", and modify the test
accordingly:

If ctl.Tag <> "KeepOpen" Then ...

Also, if the bound column of your combo box is a numeric type, even though
it displays "Closed", its value might be 1,2, etc., so the test would be
something like:

If Me![YourStatusComboBox] = 1

Hope that helps.
Sprinks
StuJol said:
i have a form designed as an invoice, i have a combo box which is linked to a
table where i get values like "waiting Payment", "closed" etc. When i select
"closed" i want all my text boxes and combo boxes on my form to be diabled.
Any ideas???
 
G

Guest

Sorry, StuJol. I assumed too much.

Access is "event-driven", meaning a number of different events are triggered
by user action. For example, when a form opens, the form's OnOpen event
occurs. When a user updates the value of a control, the control's
BeforeUpdate & AfterUpdate events occur.

When an event occurs, if an event procedure is defined for the control, then
the procedure is executed. My previous post was Visual Basic code designed
to be placed in your combo box' AfterUpdate event procedure. To clarify the
code,

- Me! is shorthand for the name of the current form

- Me![YourStatusComboBox] refers to the combo box control on your current
form. You will need to substitute the name of your combo box inside the
brackets.

- The first If..Then looks at the value of your combo box. If it is equal
to "Closed", it executes the rest of the code; otherwise, it does nothing.

- Me.Controls refers to the collection of all the controls on your form.
ctl is a variable of the type Control.

- The For Each...Next loop executes once for each control on the form. If
the name of the control is the combo box itself, which you presumably do not
want to disable, it does nothing, otherwise, it checks to see if the control
is a textbox or combobox (you can't disable a Label, for example); if it is,
it disables the control, that is, sets its Enabled property to False.

- The Tag property is a non-functional control property that Access
provides that you can use however you want. When I want to disable a series
of controls on my forms, I set their Tag property to some value, and test for
the value to decide whether to turn it off or not.

To create your event procedure, open your form in design view. Show the
properties with View, Properties, then select your combo box. Click on the
Data tab, and check the Bound Column field.

Now examine the RowSource property, which is an SQL query that fills the
rows of the combo box. The value of the combo box corresponds to the
BoundColumn (if the BoundColumn = 1, then the value will be the first field
mentioned in the RowSource query). If it is Bound to a numerical code,
rather than a text field, you will need to get this value, that corresponds
to the text "Closed".

On returning to the form, click on the Event tab, and into the AfterUpdate
field. An ellipsis will appear to the right; click on it and select Code
Builder (if necessary--depending on your configuration, it may launch
automatically).

Access will create the shell of your procedure. Cut and paste the code
between the Sub and End Sub lines and make the aforementioned changes,
inserting your combo box name in two places, keeping the brackets and quotes.
Save & exit the VBA Editor, and save your form.

Hope that helps.
Sprinks

StuJol said:
Could you please try and explain in more simple terms as im a beginner and
are finding it difficult to understand your response

many thanks

Sprinks said:
Hi, StuJol.

I'll assume that you want to keep the original combo box Enabled so that you
could theoretically change it back. Loop through the controls, and disable
all textboxes and combo boxes:

Dim ctl as Control

If Me![YourStatusComboBox] = "Closed" Then

For Each ctl In Me.Controls
If ctl.Name<> "YourStatusComboBoxName" Then
If (ctl.ControlType = acTextbox OR ctl.ControlType =
acComboBox) Then
ctl.Enabled = False
End If
End If
Next ctl

End If

Alternatively, you can use the Tag property to flag the ones you'd like to
keep open. Enter some text such as "KeepOpen", and modify the test
accordingly:

If ctl.Tag <> "KeepOpen" Then ...

Also, if the bound column of your combo box is a numeric type, even though
it displays "Closed", its value might be 1,2, etc., so the test would be
something like:

If Me![YourStatusComboBox] = 1

Hope that helps.
Sprinks
StuJol said:
i have a form designed as an invoice, i have a combo box which is linked to a
table where i get values like "waiting Payment", "closed" etc. When i select
"closed" i want all my text boxes and combo boxes on my form to be diabled.
Any ideas???
 
G

Guest

When i put in you code i get run time error 424 object required.

Any ideas

Sprinks said:
Sorry, StuJol. I assumed too much.

Access is "event-driven", meaning a number of different events are triggered
by user action. For example, when a form opens, the form's OnOpen event
occurs. When a user updates the value of a control, the control's
BeforeUpdate & AfterUpdate events occur.

When an event occurs, if an event procedure is defined for the control, then
the procedure is executed. My previous post was Visual Basic code designed
to be placed in your combo box' AfterUpdate event procedure. To clarify the
code,

- Me! is shorthand for the name of the current form

- Me![YourStatusComboBox] refers to the combo box control on your current
form. You will need to substitute the name of your combo box inside the
brackets.

- The first If..Then looks at the value of your combo box. If it is equal
to "Closed", it executes the rest of the code; otherwise, it does nothing.

- Me.Controls refers to the collection of all the controls on your form.
ctl is a variable of the type Control.

- The For Each...Next loop executes once for each control on the form. If
the name of the control is the combo box itself, which you presumably do not
want to disable, it does nothing, otherwise, it checks to see if the control
is a textbox or combobox (you can't disable a Label, for example); if it is,
it disables the control, that is, sets its Enabled property to False.

- The Tag property is a non-functional control property that Access
provides that you can use however you want. When I want to disable a series
of controls on my forms, I set their Tag property to some value, and test for
the value to decide whether to turn it off or not.

To create your event procedure, open your form in design view. Show the
properties with View, Properties, then select your combo box. Click on the
Data tab, and check the Bound Column field.

Now examine the RowSource property, which is an SQL query that fills the
rows of the combo box. The value of the combo box corresponds to the
BoundColumn (if the BoundColumn = 1, then the value will be the first field
mentioned in the RowSource query). If it is Bound to a numerical code,
rather than a text field, you will need to get this value, that corresponds
to the text "Closed".

On returning to the form, click on the Event tab, and into the AfterUpdate
field. An ellipsis will appear to the right; click on it and select Code
Builder (if necessary--depending on your configuration, it may launch
automatically).

Access will create the shell of your procedure. Cut and paste the code
between the Sub and End Sub lines and make the aforementioned changes,
inserting your combo box name in two places, keeping the brackets and quotes.
Save & exit the VBA Editor, and save your form.

Hope that helps.
Sprinks

StuJol said:
Could you please try and explain in more simple terms as im a beginner and
are finding it difficult to understand your response

many thanks

Sprinks said:
Hi, StuJol.

I'll assume that you want to keep the original combo box Enabled so that you
could theoretically change it back. Loop through the controls, and disable
all textboxes and combo boxes:

Dim ctl as Control

If Me![YourStatusComboBox] = "Closed" Then

For Each ctl In Me.Controls
If ctl.Name<> "YourStatusComboBoxName" Then
If (ctl.ControlType = acTextbox OR ctl.ControlType =
acComboBox) Then
ctl.Enabled = False
End If
End If
Next ctl

End If

Alternatively, you can use the Tag property to flag the ones you'd like to
keep open. Enter some text such as "KeepOpen", and modify the test
accordingly:

If ctl.Tag <> "KeepOpen" Then ...

Also, if the bound column of your combo box is a numeric type, even though
it displays "Closed", its value might be 1,2, etc., so the test would be
something like:

If Me![YourStatusComboBox] = 1

Hope that helps.
Sprinks
:

i have a form designed as an invoice, i have a combo box which is linked to a
table where i get values like "waiting Payment", "closed" etc. When i select
"closed" i want all my text boxes and combo boxes on my form to be diabled.
Any ideas???
 
G

Guest

Hi, StuJol. Sorry you're having problems. Please cut and paste the code
from your procedure, and the Name of the combo box control.

Sprinks

StuJol said:
When i put in you code i get run time error 424 object required.

Any ideas

Sprinks said:
Sorry, StuJol. I assumed too much.

Access is "event-driven", meaning a number of different events are triggered
by user action. For example, when a form opens, the form's OnOpen event
occurs. When a user updates the value of a control, the control's
BeforeUpdate & AfterUpdate events occur.

When an event occurs, if an event procedure is defined for the control, then
the procedure is executed. My previous post was Visual Basic code designed
to be placed in your combo box' AfterUpdate event procedure. To clarify the
code,

- Me! is shorthand for the name of the current form

- Me![YourStatusComboBox] refers to the combo box control on your current
form. You will need to substitute the name of your combo box inside the
brackets.

- The first If..Then looks at the value of your combo box. If it is equal
to "Closed", it executes the rest of the code; otherwise, it does nothing.

- Me.Controls refers to the collection of all the controls on your form.
ctl is a variable of the type Control.

- The For Each...Next loop executes once for each control on the form. If
the name of the control is the combo box itself, which you presumably do not
want to disable, it does nothing, otherwise, it checks to see if the control
is a textbox or combobox (you can't disable a Label, for example); if it is,
it disables the control, that is, sets its Enabled property to False.

- The Tag property is a non-functional control property that Access
provides that you can use however you want. When I want to disable a series
of controls on my forms, I set their Tag property to some value, and test for
the value to decide whether to turn it off or not.

To create your event procedure, open your form in design view. Show the
properties with View, Properties, then select your combo box. Click on the
Data tab, and check the Bound Column field.

Now examine the RowSource property, which is an SQL query that fills the
rows of the combo box. The value of the combo box corresponds to the
BoundColumn (if the BoundColumn = 1, then the value will be the first field
mentioned in the RowSource query). If it is Bound to a numerical code,
rather than a text field, you will need to get this value, that corresponds
to the text "Closed".

On returning to the form, click on the Event tab, and into the AfterUpdate
field. An ellipsis will appear to the right; click on it and select Code
Builder (if necessary--depending on your configuration, it may launch
automatically).

Access will create the shell of your procedure. Cut and paste the code
between the Sub and End Sub lines and make the aforementioned changes,
inserting your combo box name in two places, keeping the brackets and quotes.
Save & exit the VBA Editor, and save your form.

Hope that helps.
Sprinks

StuJol said:
Could you please try and explain in more simple terms as im a beginner and
are finding it difficult to understand your response

many thanks

:

Hi, StuJol.

I'll assume that you want to keep the original combo box Enabled so that you
could theoretically change it back. Loop through the controls, and disable
all textboxes and combo boxes:

Dim ctl as Control

If Me![YourStatusComboBox] = "Closed" Then

For Each ctl In Me.Controls
If ctl.Name<> "YourStatusComboBoxName" Then
If (ctl.ControlType = acTextbox OR ctl.ControlType =
acComboBox) Then
ctl.Enabled = False
End If
End If
Next ctl

End If

Alternatively, you can use the Tag property to flag the ones you'd like to
keep open. Enter some text such as "KeepOpen", and modify the test
accordingly:

If ctl.Tag <> "KeepOpen" Then ...

Also, if the bound column of your combo box is a numeric type, even though
it displays "Closed", its value might be 1,2, etc., so the test would be
something like:

If Me![YourStatusComboBox] = 1

Hope that helps.
Sprinks
:

i have a form designed as an invoice, i have a combo box which is linked to a
table where i get values like "waiting Payment", "closed" etc. When i select
"closed" i want all my text boxes and combo boxes on my form to be diabled.
Any ideas???
 
G

Guest

Many Thanks Sprinks,

Got it working now, it takes alot of time to get use to writing code but im
slowely making abit of progress. I've been trying to disable the combo box at
the same time all the others fields are disabled but havent been able to get
the code right. Can i ask for your assistance on more time. Also when all the
fields are disabled and you closed the form. When you open the form back up
and display a record whos combobox value is "closed", all the fields are
enabled. Can you also write some code when the form opens back up and combo
value is "closed" ALL fields are disabled so no one can ever change the
record.

I tried to cut and paste the code into the OnLoad and OnOpen events but had
no effect.



Sprinks said:
Hi, StuJol. Sorry you're having problems. Please cut and paste the code
from your procedure, and the Name of the combo box control.

Sprinks

StuJol said:
When i put in you code i get run time error 424 object required.

Any ideas

Sprinks said:
Sorry, StuJol. I assumed too much.

Access is "event-driven", meaning a number of different events are triggered
by user action. For example, when a form opens, the form's OnOpen event
occurs. When a user updates the value of a control, the control's
BeforeUpdate & AfterUpdate events occur.

When an event occurs, if an event procedure is defined for the control, then
the procedure is executed. My previous post was Visual Basic code designed
to be placed in your combo box' AfterUpdate event procedure. To clarify the
code,

- Me! is shorthand for the name of the current form

- Me![YourStatusComboBox] refers to the combo box control on your current
form. You will need to substitute the name of your combo box inside the
brackets.

- The first If..Then looks at the value of your combo box. If it is equal
to "Closed", it executes the rest of the code; otherwise, it does nothing.

- Me.Controls refers to the collection of all the controls on your form.
ctl is a variable of the type Control.

- The For Each...Next loop executes once for each control on the form. If
the name of the control is the combo box itself, which you presumably do not
want to disable, it does nothing, otherwise, it checks to see if the control
is a textbox or combobox (you can't disable a Label, for example); if it is,
it disables the control, that is, sets its Enabled property to False.

- The Tag property is a non-functional control property that Access
provides that you can use however you want. When I want to disable a series
of controls on my forms, I set their Tag property to some value, and test for
the value to decide whether to turn it off or not.

To create your event procedure, open your form in design view. Show the
properties with View, Properties, then select your combo box. Click on the
Data tab, and check the Bound Column field.

Now examine the RowSource property, which is an SQL query that fills the
rows of the combo box. The value of the combo box corresponds to the
BoundColumn (if the BoundColumn = 1, then the value will be the first field
mentioned in the RowSource query). If it is Bound to a numerical code,
rather than a text field, you will need to get this value, that corresponds
to the text "Closed".

On returning to the form, click on the Event tab, and into the AfterUpdate
field. An ellipsis will appear to the right; click on it and select Code
Builder (if necessary--depending on your configuration, it may launch
automatically).

Access will create the shell of your procedure. Cut and paste the code
between the Sub and End Sub lines and make the aforementioned changes,
inserting your combo box name in two places, keeping the brackets and quotes.
Save & exit the VBA Editor, and save your form.

Hope that helps.
Sprinks

:

Could you please try and explain in more simple terms as im a beginner and
are finding it difficult to understand your response

many thanks

:

Hi, StuJol.

I'll assume that you want to keep the original combo box Enabled so that you
could theoretically change it back. Loop through the controls, and disable
all textboxes and combo boxes:

Dim ctl as Control

If Me![YourStatusComboBox] = "Closed" Then

For Each ctl In Me.Controls
If ctl.Name<> "YourStatusComboBoxName" Then
If (ctl.ControlType = acTextbox OR ctl.ControlType =
acComboBox) Then
ctl.Enabled = False
End If
End If
Next ctl

End If

Alternatively, you can use the Tag property to flag the ones you'd like to
keep open. Enter some text such as "KeepOpen", and modify the test
accordingly:

If ctl.Tag <> "KeepOpen" Then ...

Also, if the bound column of your combo box is a numeric type, even though
it displays "Closed", its value might be 1,2, etc., so the test would be
something like:

If Me![YourStatusComboBox] = 1

Hope that helps.
Sprinks
:

i have a form designed as an invoice, i have a combo box which is linked to a
table where i get values like "waiting Payment", "closed" etc. When i select
"closed" i want all my text boxes and combo boxes on my form to be diabled.
Any ideas???
 
G

Guest

Sorry to butt in on your discussion about disabling controls from combo boxes
but this is exactly what I am trying to do as well and your explanations to a
learner are easy to understand. I however am only trying to disable a couple
of controls rather than the whole lot.

The Combo Box (called Sheets/Webs) has selections Sheets;Webs and N/A

When Sheets is selected
If Product_Specification![Sheets/Webs] = "Sheets" Then)

I want 2 controls namely ID_Core_Size and OD_Core_Size to be disabled and
the rest to be available.

Could you assist me with a code (and your very good explanations to a novice)

--
Thanks
WoodyAccess


StuJol said:
Many Thanks Sprinks,

Got it working now, it takes alot of time to get use to writing code but im
slowely making abit of progress. I've been trying to disable the combo box at
the same time all the others fields are disabled but havent been able to get
the code right. Can i ask for your assistance on more time. Also when all the
fields are disabled and you closed the form. When you open the form back up
and display a record whos combobox value is "closed", all the fields are
enabled. Can you also write some code when the form opens back up and combo
value is "closed" ALL fields are disabled so no one can ever change the
record.

I tried to cut and paste the code into the OnLoad and OnOpen events but had
no effect.



Sprinks said:
Hi, StuJol. Sorry you're having problems. Please cut and paste the code
from your procedure, and the Name of the combo box control.

Sprinks

StuJol said:
When i put in you code i get run time error 424 object required.

Any ideas

:

Sorry, StuJol. I assumed too much.

Access is "event-driven", meaning a number of different events are triggered
by user action. For example, when a form opens, the form's OnOpen event
occurs. When a user updates the value of a control, the control's
BeforeUpdate & AfterUpdate events occur.

When an event occurs, if an event procedure is defined for the control, then
the procedure is executed. My previous post was Visual Basic code designed
to be placed in your combo box' AfterUpdate event procedure. To clarify the
code,

- Me! is shorthand for the name of the current form

- Me![YourStatusComboBox] refers to the combo box control on your current
form. You will need to substitute the name of your combo box inside the
brackets.

- The first If..Then looks at the value of your combo box. If it is equal
to "Closed", it executes the rest of the code; otherwise, it does nothing.

- Me.Controls refers to the collection of all the controls on your form.
ctl is a variable of the type Control.

- The For Each...Next loop executes once for each control on the form. If
the name of the control is the combo box itself, which you presumably do not
want to disable, it does nothing, otherwise, it checks to see if the control
is a textbox or combobox (you can't disable a Label, for example); if it is,
it disables the control, that is, sets its Enabled property to False.

- The Tag property is a non-functional control property that Access
provides that you can use however you want. When I want to disable a series
of controls on my forms, I set their Tag property to some value, and test for
the value to decide whether to turn it off or not.

To create your event procedure, open your form in design view. Show the
properties with View, Properties, then select your combo box. Click on the
Data tab, and check the Bound Column field.

Now examine the RowSource property, which is an SQL query that fills the
rows of the combo box. The value of the combo box corresponds to the
BoundColumn (if the BoundColumn = 1, then the value will be the first field
mentioned in the RowSource query). If it is Bound to a numerical code,
rather than a text field, you will need to get this value, that corresponds
to the text "Closed".

On returning to the form, click on the Event tab, and into the AfterUpdate
field. An ellipsis will appear to the right; click on it and select Code
Builder (if necessary--depending on your configuration, it may launch
automatically).

Access will create the shell of your procedure. Cut and paste the code
between the Sub and End Sub lines and make the aforementioned changes,
inserting your combo box name in two places, keeping the brackets and quotes.
Save & exit the VBA Editor, and save your form.

Hope that helps.
Sprinks

:

Could you please try and explain in more simple terms as im a beginner and
are finding it difficult to understand your response

many thanks

:

Hi, StuJol.

I'll assume that you want to keep the original combo box Enabled so that you
could theoretically change it back. Loop through the controls, and disable
all textboxes and combo boxes:

Dim ctl as Control

If Me![YourStatusComboBox] = "Closed" Then

For Each ctl In Me.Controls
If ctl.Name<> "YourStatusComboBoxName" Then
If (ctl.ControlType = acTextbox OR ctl.ControlType =
acComboBox) Then
ctl.Enabled = False
End If
End If
Next ctl

End If

Alternatively, you can use the Tag property to flag the ones you'd like to
keep open. Enter some text such as "KeepOpen", and modify the test
accordingly:

If ctl.Tag <> "KeepOpen" Then ...

Also, if the bound column of your combo box is a numeric type, even though
it displays "Closed", its value might be 1,2, etc., so the test would be
something like:

If Me![YourStatusComboBox] = 1

Hope that helps.
Sprinks
:

i have a form designed as an invoice, i have a combo box which is linked to a
table where i get values like "waiting Payment", "closed" etc. When i select
"closed" i want all my text boxes and combo boxes on my form to be diabled.
Any ideas???
 
S

strive4peace

Hi Woody,

firstly, consider renaming Sheets/Webs --> Sheets_Webs

it is a bad idea to use spaces and special characters in names ... the
underscore character is okay...

rename it in your table

then, change the Name and ControlSource property on the form for the
control that shows it

on the AfterUpdate event of Sheets_Webs on your data form -->

'~~~~~~~~~~~~~~~
Dim mBoo as boolean

If nz(me.Sheets_Webs,"") <> "Sheets" then
mBoo = True
Else
mBoo = False
end if

me.someControlName.SetFocus
me.ID_Core_Size.Enabled = mBoo
me.OD_Core_Size.Enabled = mBoo
'~~~~~~~~~~~~~

If you need help getting the code in the right place, just ask...

since we are changing more than one thing, mBoo is used as a temporary
boolean variable...

Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 
G

Guest

As I stated before I am a learner and I unfortunately don't have any
programming experience so am trying this from scratch

However, I have inputted the expression you gave me into Code Builder in
AfterUpdate so have come up with this

Private Sub SheetsWebsComboBox_AfterUpdate()
Dim mBoo As Boolean

If Nz(ProductSpecification.Sheets_Webs, "") <> "Sheets" Then
mBoo = True
Else
mBoo = False
End If

ProductSpecification.Sheets_Webs.SetFocus
ProductSpecification.ID_Core_Size.Enabled = mBoo
ProductSpecification.OD_Core_Size.Enabled = mBoo
End Sub

However nothing seems to be happening when I try and input information on my
form.
What I wanted to happen was for the OD_Core_Size and ID_Core_Size text boxes
to be unable to have data put into them but they still allow text to be
written

Any ideas?

--
Thanks
WoodyAccess


strive4peace said:
Hi Woody,

firstly, consider renaming Sheets/Webs --> Sheets_Webs

it is a bad idea to use spaces and special characters in names ... the
underscore character is okay...

rename it in your table

then, change the Name and ControlSource property on the form for the
control that shows it

on the AfterUpdate event of Sheets_Webs on your data form -->

'~~~~~~~~~~~~~~~
Dim mBoo as boolean

If nz(me.Sheets_Webs,"") <> "Sheets" then
mBoo = True
Else
mBoo = False
end if

me.someControlName.SetFocus
me.ID_Core_Size.Enabled = mBoo
me.OD_Core_Size.Enabled = mBoo
'~~~~~~~~~~~~~

If you need help getting the code in the right place, just ask...

since we are changing more than one thing, mBoo is used as a temporary
boolean variable...

Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*


Sorry to butt in on your discussion about disabling controls from combo boxes
but this is exactly what I am trying to do as well and your explanations to a
learner are easy to understand. I however am only trying to disable a couple
of controls rather than the whole lot.

The Combo Box (called Sheets/Webs) has selections Sheets;Webs and N/A

When Sheets is selected
If Product_Specification![Sheets/Webs] = "Sheets" Then)

I want 2 controls namely ID_Core_Size and OD_Core_Size to be disabled and
the rest to be available.

Could you assist me with a code (and your very good explanations to a novice)
 
S

strive4peace

Hi Woody,

the procedure name indicates that your controlname is
SheetsWebsComboBox

not
Sheets_Webs

look at the procedure declaration line -->

Private Sub SheetsWebsComboBox_AfterUpdate()

control Name --> SheetsWebsComboBox
event --> AfterUpdate
procedure name --> SheetsWebsComboBox_AfterUpdate
Type --> Sub (instead of Function)
scope --> Private to the form -- may not be used by external processes


why are you putting ProductSpecification in front of the controlname?
You do something like that in a query because a query can have more than
one source... a form can have just one recordset --

Is ProductSpecification a form? If so, you need

Forms!ProductSpecification.Sheets_Webs_controlname

.... but if you are in the code behind your form, you can just refer to
the form as "Me"

--> Me.Sheets_Webs_controlname

where
Sheets_Webs_controlname
is the Name property of the control for sheets/webs.

'~~~~~~~~~~~~~~~~~~~~
PROPERTIES AND METHODS

Just like in the real world, every object has properties and methods.

Properties are like adjectives that describe an object
Methods are like verbs and define actions an object can do

For instance, you are a human and have properties such as hair color,
eye color, height, weight, ... and methods such as eat, walk, run, jump,
.... make babies -- Add to a collection :)

If you become familiar with the different types of objects that Access
can use and the properties that define them and the methods they can do
(and what triggers them), you will be on your way!

In the design view, you can show the property sheet, which will show
information for the selected item(s).

~~~~ turn on Properties window ~~~~

When you are in the design view, turn on/off the Properties window -->

1. from menu: View, Properties
OR
2. right-click and choose Properties from the shortcut menu

and then click on various objects. The properties window changes as you
change what is selected. If you have multiple objects selected, the
values for the properties they have in common will be displayed

Try it!

~~~~ Name property ~~~~

Procedures are NAMED according to the object name (except the form
object), so ALWAYS change the NAME property of any object to something
logical. For example, if you have a command button named cmdClose, its
event procedure may be something like this:

Private Sub cmdClose _Click()
If Me.Dirty Then Me.Dirty = False
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub

When the properties window is displayed and only one thing is selected,
the Name appears in the title bar of the Properties window

If multiple items are selected, you will see "Multiple Selection" on the
title bar.

~~~~ ControlSource, SourceObject ~~~~

It is important to realize that the Name is NOT what is displayed in a
control. If the control is (for instance a textbox or combo box), you
will see the ControlSource displayed.

If the object is (for instance) a subform or subreport, what you see
displayed is the SourceObject

For bound objects, I like to make the Name property match the source
property (this does not, by the way, follow naming conventions, but for
me, it eases confusion)

As always, avoid using spaces and special characters when naming objects
-- use the underscore character _ to separate and use mixed case for
readability

~~~~ FieldList ~~~~

To see what fields are available so they can be placed on a form or
report: from the menu, choose View, Field List. This is a toggle – as
is the Field List icon on the toolbar (the icon is a rectangle
containing writing with a blue title bar on top).

When you drag a field from the field list to a form or report, the field
name becomes the ControlSource and the field description becomes the
status bar text. Change the name property to something logical to you
before continuing.


Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 
G

Guest

Thanks for all the advice. I am learning without any books and trying to
learn from reading queries on websites like. So when I was writing my form
name instead of me I was obviously confused with Queries! This advice helped
a lot - I have now successfully completed my first ever code

It ended up looking like this

Private Sub Sheets_Webs_AfterUpdate()
If Me.Sheets_Webs.Text = "Sheets" Then
Me.IDCoreSize.Enabled = False
Me.ODCoreSize.Enabled = False
Else
Me.IDCoreSize.Enabled = True
Me.ODCoreSize.Enabled = True

If Me.Sheets_Webs.Text = "Webs" Then
Me.GrainComboBox.Enabled = False
Else
Me.GrainComboBox.Enabled = True

If Me.Sheets_Webs.Text = "N/A" Then
Me.IDCoreSize.Enabled = False
Me.ODCoreSize.Enabled = False
Me.GrainComboBox.Enabled = False
Else
Me.IDCoreSize.Enabled = True
Me.ODCoreSize.Enabled = True
Me.GrainComboBox.Enabled = True

End If
End If
End If
End Sub

Could it be shorter? Still unsure on all the programming language but
hopefully if i read enough posts I will get there!
 
S

strive4peace

Hi Woody,

you're welcome ;)

Congratulations!

Yes, it can be "shorter"... I also put an error handler in, so that
added a few lines...

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

Private Sub Sheets_Webs_AfterUpdate()
On Error GoTo Proc_Err

dim mBoo1 as boolean _
, mBoo2 as boolean

select case nz(Me.Sheets_Webs,"")

case "Sheets", "N/A"
mBoo1 = False
if Me.Sheets_Webs = "N/A" then
mBoo2 = False
else
mBoo2 = True
end if
case else
mBoo1 = True
mBoo2 = False

end select

Me.IDCoreSize.Enabled = mBoo1
Me.ODCoreSize.Enabled = mBoo1
Me.GrainComboBox.Enabled = mBoo2

Proc_Exit:
Exit Sub

Proc_Err:
MsgBox Err.Description, , _
"ERROR " & Err.Number & " Sheets_Webs_AfterUpdate"
'press F8 to step through code and debug
'remove next line after debugged
Stop: Resume
Resume Proc_Exit

End Sub
'~~~~~~~~~~~~~~~~~~~~

nz is Null-to-Zero

mBoo (mBoo1, mBoo2) is just some temporary boolean variable

Don't forget to indent your code ... It makes things so much easier to
follow ;)

I have a 30-page Word document I send out on Access Basics -- if you
want it, email me and put 30-page in the subject line... I also have 3
chapters of a book I am writing on VBA I can send if you request it.

Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 
G

Guest

Thanks for the tip on the email i'll send an email to your address in request
for the word document.
Just a couple more things. Now that I have dis-enabled the box can I make
sure that the boxes does not have any information in it. At the moment if
Sheets is selected and data inputed into the Grain combo Box, and then
"sheets" is changed to "webs" text in the combo box still appears?
 
S

strive4peace

Hi Woody,

you are welcome :)

Make sure you put what you want in the subject line (Access Basics) ...
otherwise I may not see your message...

"...dis-enabled the box can I make sure that the boxes does not have any
information in it..."

if you want to stick with generic code so that it can be expanded, add
this code after the End Select ...

'~~~~~~~~~~~~~~~~~~~
if not mBoo1 then
Me.IDCoreSize = null
Me.ODCoreSize = null
end if

if not mBoo2 then
Me.GrainComboBox = null
end if
'~~~~~~~~~~~~~~~~~~~

Perhaps, if you have to turn on and off controls, your data is not
properly normalized...

Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
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