Lock ComboBox

A

AnhCVL

Hi all,

I have a data entry form that linked to a data table for input, which I have
a ComboBox name CBOSelection with a set of selection, when the data entry
form load, the initial selection is empty. when the form load, I want to lock
the combobox so that when user navigate through the record, they can not
change anything but viewing the record, but able to make selection from the
drop down menu when create new record ( when the combobox data field is empty,
unlock the combobox), is it possible?

ComboBox Setting:

Name: cboSelection
Row Resoure Type: Value List
Row Value: "Eraser";"Pen";"Pencils";"Books";
Bound Collume: 1
Limit To List: Yes


I've tried the following:

Private Sub Form_Load()
If cboSelection.Text = "" Then
cboSelection.Locked = False
Else
cboSelection.Locked = False
End If
End Sub

I've also tried to use .ListIndex, .ItemData, .Value, .NotInList, .
InSelection, .Name but none seem to work, thanks for the helps.

Mark
 
O

OssieMac

Hi Mark,

I am not sure that I understand your question properly. Note that even if
the On Load event is the correct place for it then your posted code is
incorrect. You are setting Locked to false for both true and false in the If
Else statements.

When I want to lock a control based on the controls content, I place the
following code in the On Enter event. Note that I always use the Nz function
so that I do not get errors if the field is actully Null instead of just a
zero length field. (Look up Nz function in Help if you are unfamiliar with
it.)

However, you need to realize that once it is locked you also cannot delete
the data in the field but if I interpret your question correctly, you only
want to be able to enter data if it is a new record and therefore you do not
want to be able to alter or delete it.

Private Sub cboSelection_Enter()
If Nz(Me.cboSelection, "") = "" Then
Me.cboSelection.Locked = False
Else
Me.cboSelection.Locked = True
End If
End Sub
 
A

AnhCVL via AccessMonster.com

Hi there,

Thanks for the info, I am going to try it and will get back. I've changed the
setting to:

Private Sub Form_Load()
DoCmd.GoToRecord , , acNewRec
End Sub

so when the form load, it will go straight to new record so that I can
encorparate the lock functions into a command button when it is click.
Beacsue of the fact that I am allowing the data entry user to view and edit
certain information fields such as shipping date and method on the existing
database, but I want to lock certains fields so they can not change the
informations such as product types and prices once it been defined. Thanks
for the advises.

/r
Mark
Hi Mark,

I am not sure that I understand your question properly. Note that even if
the On Load event is the correct place for it then your posted code is
incorrect. You are setting Locked to false for both true and false in the If
Else statements.

When I want to lock a control based on the controls content, I place the
following code in the On Enter event. Note that I always use the Nz function
so that I do not get errors if the field is actully Null instead of just a
zero length field. (Look up Nz function in Help if you are unfamiliar with
it.)

However, you need to realize that once it is locked you also cannot delete
the data in the field but if I interpret your question correctly, you only
want to be able to enter data if it is a new record and therefore you do not
want to be able to alter or delete it.

Private Sub cboSelection_Enter()
If Nz(Me.cboSelection, "") = "" Then
Me.cboSelection.Locked = False
Else
Me.cboSelection.Locked = True
End If
End Sub
[quoted text clipped - 28 lines]
 
A

AnhCVL via AccessMonster.com

Hi there,

I tried your advises and it work perfectly, just the way I wanted. I am kinda
out-dated on the functions, I never actually knew the Nz() functions until
you brought it up. Thanks for the codes and the update.

Mark
Hi Mark,

I am not sure that I understand your question properly. Note that even if
the On Load event is the correct place for it then your posted code is
incorrect. You are setting Locked to false for both true and false in the If
Else statements.

When I want to lock a control based on the controls content, I place the
following code in the On Enter event. Note that I always use the Nz function
so that I do not get errors if the field is actully Null instead of just a
zero length field. (Look up Nz function in Help if you are unfamiliar with
it.)

However, you need to realize that once it is locked you also cannot delete
the data in the field but if I interpret your question correctly, you only
want to be able to enter data if it is a new record and therefore you do not
want to be able to alter or delete it.

Private Sub cboSelection_Enter()
If Nz(Me.cboSelection, "") = "" Then
Me.cboSelection.Locked = False
Else
Me.cboSelection.Locked = True
End If
End Sub
[quoted text clipped - 28 lines]
 
A

AnhCVL via AccessMonster.com

Hi there,

I tried your advises and it works perfectly, just the way I wanted. I am
kinda out-dated on the functions, I never actually knew the Nz() functions
until you brought it up. Thanks for the codes and the update.

Mark
Hi Mark,

I am not sure that I understand your question properly. Note that even if
the On Load event is the correct place for it then your posted code is
incorrect. You are setting Locked to false for both true and false in the If
Else statements.

When I want to lock a control based on the controls content, I place the
following code in the On Enter event. Note that I always use the Nz function
so that I do not get errors if the field is actully Null instead of just a
zero length field. (Look up Nz function in Help if you are unfamiliar with
it.)

However, you need to realize that once it is locked you also cannot delete
the data in the field but if I interpret your question correctly, you only
want to be able to enter data if it is a new record and therefore you do not
want to be able to alter or delete it.

Private Sub cboSelection_Enter()
If Nz(Me.cboSelection, "") = "" Then
Me.cboSelection.Locked = False
Else
Me.cboSelection.Locked = True
End If
End Sub
[quoted text clipped - 28 lines]
 

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