How to Conditionaly Set Cmd button Focus

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

Guest

On my Main Form I have a CmdButton I want to disable if the Focus in my
subform is the AutoNumber
and when a record is selected in the subform I want it enabled. I have tried
several different ways
setting the focus, on Dirty and several others with no success. I don't know
much about writing
code but am working hard to learn. Sorry for so many questions but I am lost.
you guys are the best.
"My field names and Primary keys are listed below."

" My Form Name = "Breeders"
My Form AutoNumber is Primary Key and it's name = "MaleID"
I have a hidden txtBox on this form named "MatingOrderID" and it shows what
record is selected
in my subform

" My subform name = "Mating Order"
My SubForm AutoNumber is Primary Key and it's name = "MatingOrderID"

By the way, Douglas Steele & wayne Morgan and the rest of you that I don't
know your names right off the bat,
All off you guys are great!!!!!
Thanks in advance.
 
On my Main Form I have a CmdButton I want to disable if the Focus in my
subform is the AutoNumber

since an autonumber field can't be manually edited anyway, how about setting
the control's Enabled property to False, so it can't receive the focus at
all. actually, since normally an Autonumber value is not meant to have
meaning to or even be seen by the user, you could just remove that control
from the subform entirely (just keep the Autonumber *field* in the subform's
RecordSource).
when a record is selected in the subform I want it enabled.

what do you mean by "when a record is selected"?

hth
 
When I have completed the design the autonumber will be hidden. They will
click in the subform "Table" to add a record. Lets say there are no records
yet. At that point I want the command button on my main form to be disabled
until a record has been entered in the subform. After records have been
entered there is a CmdButton on my Parent form that will open another form to
enter more or view record related to it, Now. Lets say there have been no
records entered at all. when they click on the subform to enter a record they
won't see it but they will be clicking into a row that contains an AutoNumber
but no value has been entered yet. At that point Also I want the CmdButton to
be Disabled.
 
When I have completed the design the autonumber will be hidden.

if the autonumber will not be bound to a visible control in the completed
design, then you don't want to write code that depends on it getting the
focus - because it never will. if i'm understanding correctly, what you
basically want is for Access to recognize whether or not there is at least
one record in the subform, and enable/disable the main form's command button
accordingly.

you don't really need to look at any fields in the subform records. in the
main form's Current event procedure, add the following, as

Me!CommandButtonName.Enabled = _
(Me!SubformCONTROLName.Form.Recordset.RecordCount > 0)

in the subform CONTROL's Exit event procedure (on the main form), add the
following, as

Me!CommandButtonName.Enabled = _
(Me!SubformCONTROLName.Form.Recordset.RecordCount > 0)

if there is a possibility that the user will want to click directly from the
subform to the command button on the main form, then add the following in
the *subform's* AfterUpdate event procedure, as

Me.Parent!CommandButtonName.Enabled = _
(Me.Recordset.RecordCount > 0)

hth
 
Thank you so much Tina,
One more thing;
lets say there are several Records in my Subform and the user is kinda in a
hurry and clicks in the CboField in my "subform" but has not made a
selection and someone or something distracts them for a moment then they turn
around and without thinking clicks on the Cmd Button to open the new form
"The CmdButton is enabled at this time because there are record values". I
want either the button to be disabled at that point or a message Box to popup
because the AutoNumber row of that record has the focus.
Shew, I hope I explained it so you see what I'm Asking.
Thanks again Tina all the other info got me a good start on it.
"Alvin"
 
I go it working. Thanks again Tina. as soon as I posted the last reply it
dawned on me what I was doing wrong. I added

If IsNull(Me![MatingOrderID]) Then
MsgBox "Enter Mating information before entering Litter Weight."
Else
End If
 
you're welcome. :)


Alvin said:
I go it working. Thanks again Tina. as soon as I posted the last reply it
dawned on me what I was doing wrong. I added

If IsNull(Me![MatingOrderID]) Then
MsgBox "Enter Mating information before entering Litter Weight."
Else
End If




tina said:
if the autonumber will not be bound to a visible control in the completed
design, then you don't want to write code that depends on it getting the
focus - because it never will. if i'm understanding correctly, what you
basically want is for Access to recognize whether or not there is at least
one record in the subform, and enable/disable the main form's command button
accordingly.

you don't really need to look at any fields in the subform records. in the
main form's Current event procedure, add the following, as

Me!CommandButtonName.Enabled = _
(Me!SubformCONTROLName.Form.Recordset.RecordCount > 0)

in the subform CONTROL's Exit event procedure (on the main form), add the
following, as

Me!CommandButtonName.Enabled = _
(Me!SubformCONTROLName.Form.Recordset.RecordCount > 0)

if there is a possibility that the user will want to click directly from the
subform to the command button on the main form, then add the following in
the *subform's* AfterUpdate event procedure, as

Me.Parent!CommandButtonName.Enabled = _
(Me.Recordset.RecordCount > 0)

hth


form
to record
they CmdButton
to in
my focus
at in
my I
am I
don't
 
Back
Top