no edit combo box?

D

DanWH

Hi, I'm working on developing a training database for work, and I have a
subform in datasheet view where the supervisor selects training topics from a
combo box.

What I want is a convienent way to always allow new records but not allow
changes in previous selections of that combo box. I've tried the lock and
enable properties but while they prohibit edits in the data I've already
chosen in that column, it doesn't let me select any new data to make a new
record. Conditional formatting doesn't work, and the setproperty macro to
selectively lock the field if it contains data always returns an error. I've
tried the main datasheet property to not allow edits, but that doesn't allow
me to update other fields on the same record that are referenced with the
training topic but need to be updated at a later time.

So basically when a combo box is used to select new records to add to a
subform datasheet, is it possible to always allow new selections while
prohibiting changing that particular field for previous records, but allow
editing of other fields that are in previous records.

Thanks
Dan
 
A

Allen Browne

Do you want to:
a) prevent changes to any fields for exising records, or
b) only prevent changes in the combo for exising records.

If (a):
1. Open the subform in design view.
2. Set these properties for the form:
AllowEdits No
AllowAdditions Yes

If (b):
1. Open the subform in design view.
2. Set the form's On Current property to:
[Event Procedure]
3. Click the Build button (...) beside this property.
Access opens the code window.

4. Add this line between the Private Sub and End Sub lines:
Private Sub Form_Current()
Me.[Combo1].Enabled = Me.NewRecord
End Sub
 
D

DanWH

Allen,

I need option b, but when I implemented it and put in my combo box name for
[combo1], I get this error everytime I click on an existing combo box with
data, "Run time error 2164, You can't disable a control while it has the
focus." After I close out the error the focus remains in the already
existing combo box and I can then change the data. Any more help will be
greatly appreciated. Using the combo box in a new record still works fine
without any errors.

Thanks
Dan

Allen Browne said:
Do you want to:
a) prevent changes to any fields for exising records, or
b) only prevent changes in the combo for exising records.

If (a):
1. Open the subform in design view.
2. Set these properties for the form:
AllowEdits No
AllowAdditions Yes

If (b):
1. Open the subform in design view.
2. Set the form's On Current property to:
[Event Procedure]
3. Click the Build button (...) beside this property.
Access opens the code window.

4. Add this line between the Private Sub and End Sub lines:
Private Sub Form_Current()
Me.[Combo1].Enabled = Me.NewRecord
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

DanWH said:
Hi, I'm working on developing a training database for work, and I have a
subform in datasheet view where the supervisor selects training topics
from a
combo box.

What I want is a convienent way to always allow new records but not allow
changes in previous selections of that combo box. I've tried the lock and
enable properties but while they prohibit edits in the data I've already
chosen in that column, it doesn't let me select any new data to make a new
record. Conditional formatting doesn't work, and the setproperty macro to
selectively lock the field if it contains data always returns an error.
I've
tried the main datasheet property to not allow edits, but that doesn't
allow
me to update other fields on the same record that are referenced with the
training topic but need to be updated at a later time.

So basically when a combo box is used to select new records to add to a
subform datasheet, is it possible to always allow new selections while
prohibiting changing that particular field for previous records, but allow
editing of other fields that are in previous records.

Thanks
Dan
 
A

Allen Browne

Perhaps you could use the Locked property instead of Enabled. That way it
won't matter if the combo does have focus.

The alternative is to use error handling code to SetFocus to something else
if the combo has focus and needs to be disabled.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

DanWH said:
Allen,

I need option b, but when I implemented it and put in my combo box name
for
[combo1], I get this error everytime I click on an existing combo box with
data, "Run time error 2164, You can't disable a control while it has the
focus." After I close out the error the focus remains in the already
existing combo box and I can then change the data. Any more help will be
greatly appreciated. Using the combo box in a new record still works fine
without any errors.

Thanks
Dan

Allen Browne said:
Do you want to:
a) prevent changes to any fields for exising records, or
b) only prevent changes in the combo for exising records.

If (a):
1. Open the subform in design view.
2. Set these properties for the form:
AllowEdits No
AllowAdditions Yes

If (b):
1. Open the subform in design view.
2. Set the form's On Current property to:
[Event Procedure]
3. Click the Build button (...) beside this property.
Access opens the code window.

4. Add this line between the Private Sub and End Sub lines:
Private Sub Form_Current()
Me.[Combo1].Enabled = Me.NewRecord
End Sub

DanWH said:
Hi, I'm working on developing a training database for work, and I have
a
subform in datasheet view where the supervisor selects training topics
from a
combo box.

What I want is a convienent way to always allow new records but not
allow
changes in previous selections of that combo box. I've tried the lock
and
enable properties but while they prohibit edits in the data I've
already
chosen in that column, it doesn't let me select any new data to make a
new
record. Conditional formatting doesn't work, and the setproperty macro
to
selectively lock the field if it contains data always returns an error.
I've
tried the main datasheet property to not allow edits, but that doesn't
allow
me to update other fields on the same record that are referenced with
the
training topic but need to be updated at a later time.

So basically when a combo box is used to select new records to add to a
subform datasheet, is it possible to always allow new selections while
prohibiting changing that particular field for previous records, but
allow
editing of other fields that are in previous records.
 
D

DanWH

Thanks Allen,

I went ahead and used 'Me.[Subject ID].Locked = not me.newrecord' and it
works PERFECTLY.

Thanks
Dan

Allen Browne said:
Perhaps you could use the Locked property instead of Enabled. That way it
won't matter if the combo does have focus.

The alternative is to use error handling code to SetFocus to something else
if the combo has focus and needs to be disabled.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

DanWH said:
Allen,

I need option b, but when I implemented it and put in my combo box name
for
[combo1], I get this error everytime I click on an existing combo box with
data, "Run time error 2164, You can't disable a control while it has the
focus." After I close out the error the focus remains in the already
existing combo box and I can then change the data. Any more help will be
greatly appreciated. Using the combo box in a new record still works fine
without any errors.

Thanks
Dan

Allen Browne said:
Do you want to:
a) prevent changes to any fields for exising records, or
b) only prevent changes in the combo for exising records.

If (a):
1. Open the subform in design view.
2. Set these properties for the form:
AllowEdits No
AllowAdditions Yes

If (b):
1. Open the subform in design view.
2. Set the form's On Current property to:
[Event Procedure]
3. Click the Build button (...) beside this property.
Access opens the code window.

4. Add this line between the Private Sub and End Sub lines:
Private Sub Form_Current()
Me.[Combo1].Enabled = Me.NewRecord
End Sub

Hi, I'm working on developing a training database for work, and I have
a
subform in datasheet view where the supervisor selects training topics
from a
combo box.

What I want is a convienent way to always allow new records but not
allow
changes in previous selections of that combo box. I've tried the lock
and
enable properties but while they prohibit edits in the data I've
already
chosen in that column, it doesn't let me select any new data to make a
new
record. Conditional formatting doesn't work, and the setproperty macro
to
selectively lock the field if it contains data always returns an error.
I've
tried the main datasheet property to not allow edits, but that doesn't
allow
me to update other fields on the same record that are referenced with
the
training topic but need to be updated at a later time.

So basically when a combo box is used to select new records to add to a
subform datasheet, is it possible to always allow new selections while
prohibiting changing that particular field for previous records, but
allow
editing of other fields that are in previous records.
 

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