If Statement

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello all,

In an Access 2003 db, I am writing an If statement on a combo box field on
After Update.

I want to disable certain fields depending upon what the user selects from
the combo box. Here is what I have done so far.

If Me.cboType = "Individual" Then
Me![Organization].Enabled = False

ElseIf Me.cboType = "Organization" Then
Me![Organization].Enabled = True

Else
Me![LastName].Enabled = True
Me![FirstName].Enabled = True
End If
End Sub

When Organization is selected, the appropariate field is enabled, the last
name is disabled, first name is enabled.

When Individual is selected, Organization and Last Name fields are both
disabled. First Name is enabled.

Can anyone help?

Thanks Connie
 
Have you tried explicitly setting the properties for all of the fields:

If Me.cboType = "Individual" Then
Me![Organization].Enabled = False
Me![LastName].Enabled = True
Me![FirstName].Enabled = True
ElseIf Me.cboType = "Organization" Then
Me![Organization].Enabled = True
Me![LastName].Enabled = True
Me![FirstName].Enabled = True
Else
Me![LastName].Enabled = True
Me![FirstName].Enabled = True
End If

Hello all,

In an Access 2003 db, I am writing an If statement on a combo box field on
After Update.

I want to disable certain fields depending upon what the user selects from
the combo box. Here is what I have done so far.

If Me.cboType = "Individual" Then
Me![Organization].Enabled = False

ElseIf Me.cboType = "Organization" Then
Me![Organization].Enabled = True

Else
Me![LastName].Enabled = True
Me![FirstName].Enabled = True
End If
End Sub

When Organization is selected, the appropariate field is enabled, the last
name is disabled, first name is enabled.

When Individual is selected, Organization and Last Name fields are both
disabled. First Name is enabled.

Can anyone help?

Thanks Connie
 
Thanks very much for your help. I just changed the true/false where needed
and it worked.

However, a strange thing happens and I'm not sure how to fix it. I go to a
new record and choose, for eg: Organization. The Last Name and First Name
fields are disabled as planned and I complete the record. Without closing
the form, I do a search for other records. All of the Last Name and First
name fields are disabled, even if the record is designated "Individual". The
same thing happens if I create a new record and choose "Individual". All
Organization fields are disabled for all records in the database.

When I close the form and reopen. All fields are enabled.

Do you have any suggestions?

Connie


kingston via AccessMonster.com said:
Have you tried explicitly setting the properties for all of the fields:

If Me.cboType = "Individual" Then
Me![Organization].Enabled = False
Me![LastName].Enabled = True
Me![FirstName].Enabled = True
ElseIf Me.cboType = "Organization" Then
Me![Organization].Enabled = True
Me![LastName].Enabled = True
Me![FirstName].Enabled = True
Else
Me![LastName].Enabled = True
Me![FirstName].Enabled = True
End If

Hello all,

In an Access 2003 db, I am writing an If statement on a combo box field on
After Update.

I want to disable certain fields depending upon what the user selects from
the combo box. Here is what I have done so far.

If Me.cboType = "Individual" Then
Me![Organization].Enabled = False

ElseIf Me.cboType = "Organization" Then
Me![Organization].Enabled = True

Else
Me![LastName].Enabled = True
Me![FirstName].Enabled = True
End If
End Sub

When Organization is selected, the appropariate field is enabled, the last
name is disabled, first name is enabled.

When Individual is selected, Organization and Last Name fields are both
disabled. First Name is enabled.

Can anyone help?

Thanks Connie
 
When you enable or disable a control, this setting is applied to the form
object; data has no bearing on the setting. What you are doing is using an
event or evaluate a data point to set a control's property (for the form and
regardless of data). This is why the control is in the same state for every
record.

To change this somewhat, use the form's OnCurrent event to evaluate the field
and set the property when entering a record. If you are using continuous
forms, you will see all of the controls change together, and odd as it may
appear, they will all correspond to the current record. However, the
controls will be available or unavailable as required.
Thanks very much for your help. I just changed the true/false where needed
and it worked.

However, a strange thing happens and I'm not sure how to fix it. I go to a
new record and choose, for eg: Organization. The Last Name and First Name
fields are disabled as planned and I complete the record. Without closing
the form, I do a search for other records. All of the Last Name and First
name fields are disabled, even if the record is designated "Individual". The
same thing happens if I create a new record and choose "Individual". All
Organization fields are disabled for all records in the database.

When I close the form and reopen. All fields are enabled.

Do you have any suggestions?

Connie
Have you tried explicitly setting the properties for all of the fields:
[quoted text clipped - 40 lines]
 
Thanks. I understand. I am going to try the oncurrent because it won't work
for users the way it is.

Connie

kingston via AccessMonster.com said:
When you enable or disable a control, this setting is applied to the form
object; data has no bearing on the setting. What you are doing is using an
event or evaluate a data point to set a control's property (for the form and
regardless of data). This is why the control is in the same state for every
record.

To change this somewhat, use the form's OnCurrent event to evaluate the field
and set the property when entering a record. If you are using continuous
forms, you will see all of the controls change together, and odd as it may
appear, they will all correspond to the current record. However, the
controls will be available or unavailable as required.
Thanks very much for your help. I just changed the true/false where needed
and it worked.

However, a strange thing happens and I'm not sure how to fix it. I go to a
new record and choose, for eg: Organization. The Last Name and First Name
fields are disabled as planned and I complete the record. Without closing
the form, I do a search for other records. All of the Last Name and First
name fields are disabled, even if the record is designated "Individual". The
same thing happens if I create a new record and choose "Individual". All
Organization fields are disabled for all records in the database.

When I close the form and reopen. All fields are enabled.

Do you have any suggestions?

Connie
Have you tried explicitly setting the properties for all of the fields:
[quoted text clipped - 40 lines]
Thanks Connie
 
Back
Top