Hello
I have a single form, and want to require the user to make a selection
from a serialnumber ComboBox before being allowed to enter any other
textboxes. Also, the user should be allowed to click on an Exit button
I created and get a response.
The following code works fine without the ExitButton issue:
Private Sub SerialCombo_Exit(Cancel As Integer)
Dim Ctl As Control
If IsNull(SerDevCombo) Then
MsgBox "You must enter a serial#"
Me.AnyOtherField.SetFocus 'acts as a refresh
Me.SerialCombo.SetFocus 'return to field since it is empty
End If
End Sub
MY PROBLEM IS INCLUDING THE CHECK FOR a change of focus when
clicking on the ExitButton. I tried many different methods.
If Not (Screen.ActiveControl.Name <> "ExitButton") Then
ThankYou 17 2229 Ap******@gmail.com wrote: Hello
I have a single form, and want to require the user to make a selection from a serialnumber ComboBox before being allowed to enter any other textboxes. Also, the user should be allowed to click on an Exit button I created and get a response.
The following code works fine without the ExitButton issue:
Private Sub SerialCombo_Exit(Cancel As Integer) Dim Ctl As Control If IsNull(SerDevCombo) Then MsgBox "You must enter a serial#" Me.AnyOtherField.SetFocus 'acts as a refresh Me.SerialCombo.SetFocus 'return to field since it is empty End If End Sub
MY PROBLEM IS INCLUDING THE CHECK FOR a change of focus when clicking on the ExitButton. I tried many different methods.
If Not (Screen.ActiveControl.Name <> "ExitButton") Then
ThankYou
I created a combo box and a command button to close/exit. Here's the
code for my combo using the OnExit method.
Private Sub Combo0_Exit(Cancel As Integer)
If IsNull(Me.Combo0) Then
Cancel = True
MsgBox "Select an item"
End If
End Sub
This works...except if I press the X button to close the window.
Now if you wanted to allow the person to exit even if the serial no is
null, what you could set, in design mode, all of the textbox controls to
Enabled = True/Locked = True. This permits only the combo to be updated
or exit button to be pressed.
In the AfterUpdate event for the combo you could do something like
If Not IsNull(Me.Combo0) Then
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
ctl.Locked = False
Endif
Next
End If
nice solution, salad. there is a gap, though - the user could enter
something in the combo box and exit the control, then go back and remove the
value and again exit the control. at that point, all the other controls are
still unlocked. how about modifying your code a little, to remove the outer
If statement, as
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
ctl.Locked = IsNull(Me.Combo0)
End If
Next
hth
"salad" <oi*@vinegar.com> wrote in message
news:Oh***************@newsread2.news.pas.earthlin k.net... Ap******@gmail.com wrote: Hello
I have a single form, and want to require the user to make a selection from a serialnumber ComboBox before being allowed to enter any other textboxes. Also, the user should be allowed to click on an Exit button I created and get a response.
The following code works fine without the ExitButton issue:
Private Sub SerialCombo_Exit(Cancel As Integer) Dim Ctl As Control If IsNull(SerDevCombo) Then MsgBox "You must enter a serial#" Me.AnyOtherField.SetFocus 'acts as a refresh Me.SerialCombo.SetFocus 'return to field since it is empty End If End Sub
MY PROBLEM IS INCLUDING THE CHECK FOR a change of focus when clicking on the ExitButton. I tried many different methods.
If Not (Screen.ActiveControl.Name <> "ExitButton") Then
ThankYou I created a combo box and a command button to close/exit. Here's the code for my combo using the OnExit method.
Private Sub Combo0_Exit(Cancel As Integer) If IsNull(Me.Combo0) Then Cancel = True MsgBox "Select an item" End If End Sub
This works...except if I press the X button to close the window.
Now if you wanted to allow the person to exit even if the serial no is null, what you could set, in design mode, all of the textbox controls to Enabled = True/Locked = True. This permits only the combo to be updated or exit button to be pressed.
In the AfterUpdate event for the combo you could do something like If Not IsNull(Me.Combo0) Then Dim ctl As Control For Each ctl In Me.Controls If ctl.ControlType = acTextBox Then ctl.Locked = False Endif Next End If
tina wrote: nice solution, salad. there is a gap, though - the user could enter something in the combo box and exit the control, then go back and remove the value and again exit the control. at that point, all the other controls are still unlocked. how about modifying your code a little, to remove the outer If statement, as
Dim ctl As Control
For Each ctl In Me.Controls If ctl.ControlType = acTextBox Then ctl.Locked = IsNull(Me.Combo0) End If Next
hth
Much better.
This solution still does not meet the OP's requirements !!
<< before being allowed to enter any other textboxes>>
The user can still enter any other textbox and he probably will become
confused because he can not enter data in the textbox. The solution that
meets the OP's requirements is:
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
ctl.Locked = IsNull(Me.Combo0)
ctl.Enabled = Not IsNull(Me.Combo0)
End If
Next
--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
Over 1175 users have come to me from the newsgroups requesting help re******@pcdatasheet.com
"salad" <oi*@vinegar.com> wrote in message
news:Wy***************@newsread2.news.pas.earthlin k.net... tina wrote:
nice solution, salad. there is a gap, though - the user could enter something in the combo box and exit the control, then go back and remove the value and again exit the control. at that point, all the other controls are still unlocked. how about modifying your code a little, to remove the outer If statement, as
Dim ctl As Control
For Each ctl In Me.Controls If ctl.ControlType = acTextBox Then ctl.Locked = IsNull(Me.Combo0) End If Next
hth Much better.
"PC D" <fa***@email.com> schreef in bericht news:WR*****************@newsread1.news.atl.earthl ink.net... PC Datasheet Your Resource For Help With Access, Excel And Word Applications 'Resource ???? Over 1175 users have come to me from the newsgroups requesting help '1175 users ???? re******@pcdatasheet.com
--
To Steve:
Why PC D this time? Why not PCD anymore, or Access Resource or Help available or why not just PC DataSheet?
You think that changing names is vital for you?
Why don't you just get lost? No-one wants your advertising/job hunting here!
Over 600!! users from the newsgroups have visited the website to read what kind of a 'resource' you are... (rapidly increasing..)
To the original poster:
Most people here have a common belief that the newsgroups are for *free exchange of information*.
But Steve is a notorious job hunter in these groups, always trying to sell his services.
Before you intend to do business with him look at: http://home.tiscali.nl/arracom/whoissteve.html
Arno R
well, considering that both salad and i suggested that the code be run in
the combo box control's AfterUpdate event - you're correct, it doesn't meet
the OP's requirements. there's nothing to stop the user from tabbing through
that control without making any changes, thus leaving the other controls
unlocked. but your revised code doesn't address that problem, either; it
simply enables/disables the other controls *again, only when the user first
makes a change in the combo box control*. disabling controls does nothing
more to make them unusable than simply locking them, though i'd agree with
you that it gives the user a visual cue that the controls unavailable.
i'd say that all three of us missed the boat here, to one degree or another.
the code i posted should be added to the form's Current event, in addition
to the combo box control's AfterUpdate event. that should take care of the
issue, unless i'm overlooking something - again.
hth
"PC D" <fa***@email.com> wrote in message
news:WR*****************@newsread1.news.atl.earthl ink.net... This solution still does not meet the OP's requirements !!
<< before being allowed to enter any other textboxes>>
The user can still enter any other textbox and he probably will become confused because he can not enter data in the textbox. The solution that meets the OP's requirements is:
Dim ctl As Control
For Each ctl In Me.Controls If ctl.ControlType = acTextBox Then ctl.Locked = IsNull(Me.Combo0) ctl.Enabled = Not IsNull(Me.Combo0) End If Next
-- PC Datasheet Your Resource For Help With Access, Excel And Word Applications Over 1175 users have come to me from the newsgroups requesting
help re******@pcdatasheet.com
"salad" <oi*@vinegar.com> wrote in message news:Wy***************@newsread2.news.pas.earthlin k.net... tina wrote:
nice solution, salad. there is a gap, though - the user could enter something in the combo box and exit the control, then go back and
remove the value and again exit the control. at that point, all the other controls are still unlocked. how about modifying your code a little, to remove the outer If statement, as
Dim ctl As Control
For Each ctl In Me.Controls If ctl.ControlType = acTextBox Then ctl.Locked = IsNull(Me.Combo0) End If Next
hth Much better.
I agree totally with your last comment Tina. Having the same concerns
and realizing that I would have had to alter a substantial number of
things in
my form to go your suggested route. I instead choose to repost an
alternate
idea. But it really surprised me that this idea would be so difficult
to implement.
Others have made suggestions, but I just can't seem to make it happen!
My alternate Post was:
If I am in a combobox, is there are way of determining which control
was clicked outside the combobox, before I actually leave the combobox?
yes, i've been following that thread too, Apex. and the answer is: AFAIK,
no. when you click, or tab, from one control to another, the events for the
first control (such as BeforeUpdate, AfterUpdate, and Exit) run before the
events for the second control (such as the second control). so the identity
of the "next" control isn't available at the time that the events of the
"current" control run.
my (and salad's) alternate solution, when presented in its' entirety, is
really simple enough. i'd suggest a private procedure in the form's module,
as
Private Sub isLocked()
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
ctl.Locked = IsNull(Me.Combo0)
End If
Next
End Sub
if you need to manage other controls such as combo boxes, beside the textbox
controls, you can add them to the If Statement, such as
If ctl.ControlType = acTextBox Or _
ct.ControlType = acComboBox Then
in the form's Current event, and the combo box's AfterUpdate event, simply
call the sub, as
isLocked
this is a pretty standard solution to the issue of managing controls on a
form based on a value in one of them. if it doesn't suit your needs, i'm
afraid i have no other suggestions to offer.
hth
<Ap******@gmail.com> wrote in message
news:11*********************@i39g2000cwa.googlegro ups.com... I agree totally with your last comment Tina. Having the same concerns and realizing that I would have had to alter a substantial number of things in my form to go your suggested route. I instead choose to repost an alternate idea. But it really surprised me that this idea would be so difficult to implement. Others have made suggestions, but I just can't seem to make it happen!
My alternate Post was: If I am in a combobox, is there are way of determining which control was clicked outside the combobox, before I actually leave the combobox?
Tina
Thankyou for your help!
Greg
you're welcome, good luck! :)
<Ap******@gmail.com> wrote in message
news:11*********************@e56g2000cwe.googlegro ups.com... Tina
Thankyou for your help!
Greg
1. Does the Combo have to be entered first?
2. Or is it sufficient to say that it must be entered before the record
can be saved?
No 2 is the easiest one to deal with. In the Forms BeforeUpdate event:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me!MyCombo) Then
MsgBox "Enter a value in MyCombo"
Cancel=True
End If
End Sub
No 1 is a bit trickier, as the others trying to answer this have shown.
What I have done in similar scenarios is (you could use Visible or
Locked depending on what you want to see visually):
Private Sub Form_Current()
SetControls
End Sub
Private Sub MyCombo_AfterUpdate()
SetControls
End Sub
Sub SetControls()
'Each control separately or a loop if all controls to be
'Invisible/locked. Make sure if you loop to exclude
'MyCombo from being locked
If IsNull(Me!MyCombo) Then
Me!Control1.Visible = False
Me!Control2.Visible = False
....
Me!Controlx.Visible = False
Else
Me!Control1.Visible = True
Me!Control2.Visible = True
....
Me!Controlx.Visible = True
End If
End Sub
HTH
--
Bri
your #2 solution is a good, standard solution to this type of situation,
Bri. to save yourself all the code-writing involved in listing each control
explicitly (and twice) in an If statement, though, you might want to give
salad's looping code a try, with the "True/False" toggle that i added to it.
the end result is the same, it's just the difference in time saved between
writing 6 lines of code vs a potentially large number of lines depending on
the number of controls. also, code maintenance is easier with the looping
code; if you add a new control to the form, you don't need to change the
looping code at all, vs needing to remember to add that control to the If
statement.
hth
"Bri" <no*@here.com> wrote in message news:XEw_f.14458$gO.8016@pd7tw3no... 1. Does the Combo have to be entered first? 2. Or is it sufficient to say that it must be entered before the record can be saved?
No 2 is the easiest one to deal with. In the Forms BeforeUpdate event:
Private Sub Form_BeforeUpdate(Cancel As Integer) If IsNull(Me!MyCombo) Then MsgBox "Enter a value in MyCombo" Cancel=True End If End Sub
No 1 is a bit trickier, as the others trying to answer this have shown. What I have done in similar scenarios is (you could use Visible or Locked depending on what you want to see visually):
Private Sub Form_Current() SetControls End Sub
Private Sub MyCombo_AfterUpdate() SetControls End Sub
Sub SetControls() 'Each control separately or a loop if all controls to be 'Invisible/locked. Make sure if you loop to exclude 'MyCombo from being locked If IsNull(Me!MyCombo) Then Me!Control1.Visible = False Me!Control2.Visible = False ... Me!Controlx.Visible = False Else Me!Control1.Visible = True Me!Control2.Visible = True ... Me!Controlx.Visible = True End If End Sub
HTH
-- Bri Ap******@gmail.com wrote: I agree totally with your last comment Tina. Having the same concerns and realizing that I would have had to alter a substantial number of things in my form to go your suggested route. I instead choose to repost an alternate idea. But it really surprised me that this idea would be so difficult to implement. Others have made suggestions, but I just can't seem to make it happen!
My alternate Post was: If I am in a combobox, is there are way of determining which control was clicked outside the combobox, before I actually leave the combobox?
I totally disagree with your comments. It is not difficult to
implement. You're just to lazy.
I supplied a suggestion without knowing anything about your process or
form so I provided something minimal. I write mostly aircode in
responses to people, and my response to your problem was aircode. Some
posters like you expect that people put aside their lives and provide
free advice like some Mother Thresa to people like you that are too lazy
to figure something out themselves...especially when provided a method
or solution. The only reason you can't make it happen is due to the
fact you aren't qualified to do the work.
You got some ideas from a few of us. Use your imagination and make them
work for you.
wow, salad, take it down a notch, hon. personal attacks aren't appropriate
in this forum.
"salad" <oi*@vinegar.com> wrote in message
news:i0****************@newsread3.news.pas.earthli nk.net... Ap******@gmail.com wrote: I agree totally with your last comment Tina. Having the same concerns and realizing that I would have had to alter a substantial number of things in my form to go your suggested route. I instead choose to repost an alternate idea. But it really surprised me that this idea would be so difficult to implement. Others have made suggestions, but I just can't seem to make it happen!
My alternate Post was: If I am in a combobox, is there are way of determining which control was clicked outside the combobox, before I actually leave the combobox? I totally disagree with your comments. It is not difficult to implement. You're just to lazy.
I supplied a suggestion without knowing anything about your process or form so I provided something minimal. I write mostly aircode in responses to people, and my response to your problem was aircode. Some posters like you expect that people put aside their lives and provide free advice like some Mother Thresa to people like you that are too lazy to figure something out themselves...especially when provided a method or solution. The only reason you can't make it happen is due to the fact you aren't qualified to do the work.
You got some ideas from a few of us. Use your imagination and make them work for you.
Salad. I am very grateful to you for your suggestion. It was an
excellent option,
just not one suitable for my application because of the intended
behavior of my
form, and what would be required to re-engineer what I was already
happy with.
I believe you misunderstood my comments.
I can assure you that I am not lazy. Just notice that same of my posts
are beyond
1:00AM. Further, I am new to Access (2 Months) and do need the help of
the group,
and will in time return the favors. And finally, I do not liken you to
Mother Thresa.
You behave more like Mother Fxxxxx.
Sorry To Have Bothered You!
tina wrote: your #2 solution is a good, standard solution to this type of situation, Bri. to save yourself all the code-writing involved in listing each control explicitly (and twice) in an If statement, though, you might want to give salad's looping code a try, with the "True/False" toggle that i added to it. the end result is the same, it's just the difference in time saved between writing 6 lines of code vs a potentially large number of lines depending on the number of controls. also, code maintenance is easier with the looping code; if you add a new control to the form, you don't need to change the looping code at all, vs needing to remember to add that control to the If statement. 'Each control separately or a loop if all controls to be 'Invisible/locked. Make sure if you loop to exclude 'MyCombo from being locked
I did mention the loop in the code comment above, but as I had seen that
it had been demonstrated in another post, I only wanted to point out
that the controlling control needed to be excluded from the action
inside the loop. I offered the alternative in case it was only some
specific controls that needed to be invisible/locked.
--
Bri Ap******@gmail.com wrote: Hello
I have a single form, and want to require the user to make a selection from a serialnumber ComboBox before being allowed to enter any other textboxes. Also, the user should be allowed to click on an Exit button I created and get a response.
The following code works fine without the ExitButton issue:
Private Sub SerialCombo_Exit(Cancel As Integer) Dim Ctl As Control If IsNull(SerDevCombo) Then MsgBox "You must enter a serial#" Me.AnyOtherField.SetFocus 'acts as a refresh Me.SerialCombo.SetFocus 'return to field since it is empty End If End Sub
MY PROBLEM IS INCLUDING THE CHECK FOR a change of focus when clicking on the ExitButton. I tried many different methods.
If Not (Screen.ActiveControl.Name <> "ExitButton") Then
ThankYou
I tried to come up with something that would handle as many of the
posted objections as possible. Here's some code behind
frmHoldingPattern:
'Begin code behind form----------
Option Compare Database
Option Explicit
Dim boolNormalExit As Boolean
Private Sub cmdExit_Click()
boolNormalExit = True
DoCmd.Close acForm, Me.Name
End Sub
Private Sub Form_Load()
SerialCombo.SetFocus
boolNormalExit = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Force the user to exit using the command button only
If boolNormalExit = False Then
MsgBox ("You must use the Exit button to exit.")
Cancel = True
End If
End Sub
Private Sub OtherCombo_GotFocus()
'Call FocusMove is optional for any comboboxes
End Sub
Private Sub txtOne_GotFocus()
Call FocusMove
End Sub
Private Sub txtTwo_GotFocus()
Call FocusMove
End Sub
Private Sub FocusMove()
If IsNull(SerialCombo.Value) Then
MsgBox ("You must supply a serial number before entering a text box
unless exiting.")
SerialCombo.SetFocus
End If
End Sub
'End code behind form--------
It's not as automatic as looping through the form's controls but may be
close to what you want. Tabbing into or clicking on a textbox gives
the user a message before going back to the combobox. It doesn't
involve locking or disabling controls. It satisfies Tina's revisit
objection. Clicking the X button to close the window results in a
message that along with the other message seems to allay PC D's fears
about the user becoming confused. It allows other comboboxes to be
edited before continuing on with its functionality. It doesn't deal
with saving the record though. Also, you'd need to remember to put the
GotFocus event on new textboxes. Perhaps this code can be a starting
point for something. Disclaimer: I'm not positive I understood the
question.
James A. Fortune CD********@FortuneJames.com
Though this be madness, yet there is method in 't. :-)
-- Polonius' Aside From Hamlet (II, ii, 206) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Harlin Seritt |
last post by:
I've created a ghetto-ized ComboBox that should work nicely for Tkinter
(unfortunately no dropdown capabilities yet).
I've found why it's such a pain in the @ss to create one. You have to...
|
by: Susan Bricker |
last post by:
The following error:
"The current field must match the join key '?' in the table that seves
as t the 'one' side of one-to-many relationship. Enter a record in the
'one' side table with the...
|
by: Susan Bricker |
last post by:
I went back to read my post and found an error in my description ...
here is the post, again, corrected:
The following error:
"The current field must match the join key '?' in the table that...
|
by: Krul |
last post by:
I like to have a blank entry at top of the combobox list, so the user
is able to clear the combobox.
Right now, the form displays a empty entry on load, but after chosen a
value once, it is not...
|
by: Tosch |
last post by:
I have a combobox where a user can select a zoom factor or enter a
zoom factor.
I tried to limit entry into the combobox to numbers only by catching
the keydown event and setting e.handled = true...
|
by: peter78 |
last post by:
I wanted to implement an autocomplete feature on the combobox where you
would type in partial text and it would try to match it for you. It
doesn't exist in .Net yet, but I'm guessing it will in...
|
by: Steve B. |
last post by:
Without adding whitespace to the ComboBox datasource is there a way I can add
a blank entry or, a reset entry, to the ComboBox dropdown
Thanks
Steve
|
by: tizmagik |
last post by:
I have a combobox on a continuous form that has a recordsource that is
set upon Form_Load event via VBA (based on initial form data and
external form data entered). For data entry purposes the...
|
by: EManning |
last post by:
I have a combobox whose rowsource is a union query. This query
displays a person's name in "lastname, firstname" format and in
"firstname lastname" format. The query results look like this:
...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |