Hello,
I have a combo box [PHIconsultantcombo] on a form that I would like to 'lock' the selection of after the user makes a selection, then either moves to the next record or saves the form. This selection will therefore be unable to be changed afterwards.
From my research, I'm assuming that the following code needs to be placed into form_current event somehow: - Private Sub PHIconsultantcombo_LostFocus()
-
PHIconsultantcombo.Locked = (PHIconsultantcombo.Text <> "")
-
-
End Sub
My current form_current event code looks like this: - Private Sub Form_Current()
-
Me.RecordsetClone.MoveLast
-
Me.RecordsetClone.MoveFirst
-
-
If Me.Lead_State <> "WA" Then
-
Me.Statewarning = Null
-
Else
-
Me.Statewarning = "Note: THC is not sold in WA"
-
End If
-
-
If Me.RecordsetClone.RecordCount = CurrentRecord Then
-
Me.but_next.Enabled = False
-
Me.but_last.Enabled = False
-
Else
-
Me.but_next.Enabled = True
-
Me.but_last.Enabled = True
-
End If
-
-
If CurrentRecord = 1 Then
-
Me.but_previous.Enabled = False
-
Me.but_first.Enabled = False
-
Else
-
Me.but_previous.Enabled = True
-
Me.but_first.Enabled = True
-
End If
-
End Sub
How do I add the lostfocus code to the current event form code? Or am I on completely the wrong track?
9 6406
If it's a bound control, use AfterUpdate rather than LostFocus -
Private Sub PHIconsultantcombo_AfterUpdate()
-
If PHIconsultantcombo.Text <> "" then = PHIconsultantcombo.Locked = True
-
End Sub
-
Would that work? It doesn't need to be inside the form_current event does it?
To begin with you need to use the .Value property, not the .Text property.Text is only valid when the control has focus.
And yes, it does have to be in the OnCurrent event! Anytime you set some kind of formatting or properties (such as colors, visibility, enabling) in the AfterUpdate event of a control, you also have to include the code in the form's OnCurrent event. Otherwise, if you move from a record where, for example, a combobox is enabled, to a record where it should be disabled, it will inappropriately be enabled in the second record!
Linq ;0)>
Thanks missinglinq.
Just confirming - I therefore need to use the following code: -
Private Sub PHIconsultantcombo_LostFocus()
-
PHIconsultantcombo.Locked = (PHIconsultantcombo.Value <> "")
-
Since I'm an Access Newbie, how would I best incorporate this into my current event code shown in my question?
Thanks again.
I'd just place it as the first line, immediately following Private Sub Form_Current()
Linq ;0)>
Hi again,
I've now placed the code at the top of form_current. This has managed to prevent combo box changes being made to existing records. However when I go to create a new record I'm met with the error:
Run-time error 94: Invalid use of Null
I select debug and the 'PHIconsultantcombo.Locked' line is highlighted as being the section of code causing the problem.
Is there anyway to overcome this and ensure that any combobox value can be selected for a newly created record?
Thanks.
My new code is below -
Private Sub Form_Current()
-
PHIconsultantcombo.Locked = (PHIconsultantcombo.Value <> "")
-
Me.RecordsetClone.MoveLast
-
Me.RecordsetClone.MoveFirst
-
-
-
If Me.Lead_State <> "WA" Then
-
Me.Statewarning = Null
-
Else
-
Me.Statewarning = "Note: THC is not sold in WA"
-
End If
-
-
If Me.RecordsetClone.RecordCount = CurrentRecord Then
-
Me.but_next.Enabled = False
-
Me.but_last.Enabled = False
-
Else
-
Me.but_next.Enabled = True
-
Me.but_last.Enabled = True
-
End If
-
-
If CurrentRecord = 1 Then
-
Me.but_previous.Enabled = False
-
Me.but_first.Enabled = False
-
Else
-
Me.but_previous.Enabled = True
-
Me.but_first.Enabled = True
-
End If
-
End Sub
-
Change - PHIconsultantcombo.Locked = (PHIconsultantcombo.Value <> "")
-
to - If Not Me.NewRecord Then
-
PHIconsultantcombo.Locked = Not IsNull(PHIconsultantcombo.Value)
-
Else
-
PHIconsultantcombo.Locked = False
-
End If
-
Linq ;0)>
Thanks so much for your help missinglinq,
Your solution works perfectly.
Glad we could help!
Linq ;0)> NeoPa 32,556
Recognized Expert Moderator MVP
I like the way you assign a boolean result to the boolean attribute, and also that you noticed the use of the [ CODE ] tags after your first post and used them subsequently :)
For your current logic, a single line, similar to your first will work (although Linq's code works perfectly too of course). - Me.PHIconsultantcombo.Locked = _
-
Not (IsNull(Me.PHIconsultantcombo) Or Me.NewRecord)
I would question the logic of locking the ComboBox after updates (to the control) though, and suggest that it should (possibly - only you know if this makes better sense) lock it only for saved records (with a selected value obviously). To enable this logic, simply use the same code, but only in the OnCurrent event procedure (not in AfterUpdate).
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Steve |
last post by:
C#
I have some combo boxes, full of lookup descriptions. When I retrieve a
dataset for my record, the values that need binding to the combos are the
actual record IDs that relate to these...
|
by: Matt Evans |
last post by:
Hi, this must have been asked for before, but I cannot see it.
Hopefully this is very simple.
I have a form which shows everything from a table. In this table is a
picture field called photo....
|
by: Maria Joao |
last post by:
I have two synchronized combo boxes and after the selection of the
desired record, I need the user to open the related report, by
pressing a button.
My problem is that a combo box doesn't update...
|
by: Danny |
last post by:
I have a combo box look up and list items in a table, it is not bound.
It works fine but how can I prevent the users from entering in there own
data?
i have an 'on change' event that when it...
|
by: Cillies |
last post by:
Hi All,
This message is a continuation of an earlier post, so please accept my
apologies as I believe I would get a better response this way.
Problem:
I have 4 combo boxes which I want to...
| |
by: Will |
last post by:
I have a combo box on a form which is based on table tblMachine. On that
combo box I have four columns visible MachineNumber, description, location
and type. The bound column is the MachineNumber...
|
by: meganrobertson22 |
last post by:
Hi Everyone-
I have a question about how to add and then use the "All" selection in
a combo box. I am trying to figure out how to:
(1) add "All" as a selection to a combo box and then
(2)...
|
by: bammo |
last post by:
MS Access 2003, Windows XP SP2, VBA
I have a continuous form that allows edits and filters, but not deletions or additions. I filter the form based on combining selections the user makes in...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |