Moving to next control

  • Thread starter Thread starter shanesullaway via AccessMonster.com
  • Start date Start date
S

shanesullaway via AccessMonster.com

On my form 'frmCustomers', I have a subform, which is unbound. I use 10
cmdButtons on frmCustomers to set the SourceObject of the subform after a
cmdButton receives the focus. Use one cmdButton as an example. cmdFunding,
would set the SourceObject of the subform to display the funding sources for
a customer.

I have a situation that I have not figured a way past. If there has not been
a funding source entered for the customer then when cmdFunding receives the
focus I have it fire a messge to the user telling them no funding source has
been entered yet and would they like to enter a new one. On the "yes" side of
the message I have it handled but the "no" side is the one that's eatting my
lunch. What I would like to have happen after the user chooses "no" is to
have the focus move to the next command button, however I have not been able
to pull it off....yet! I don't want to use {SendKeys} since I've read so many
post about that being a bad idea. Do any of ya'll have a suggestion?

Any help would be appricated,
Shane

P.S. If using an array is part of your answer. I'm now very little about how
to do one so a little code example would be very helpful.
 
Thanks for the reply Rob. I wish it was as easy as that. These 10
cmdButtons are nested in a Select statement and I need this to be more
dynamic than that since I won't know for sure which one of the 10 cmdButtons
the user is on to make the focus go to the next control.

Shane

Rob said:
Me.NameOfCmdButtonToGetFocus.SetFocus

Rob
On my form 'frmCustomers', I have a subform, which is unbound. I use 10
cmdButtons on frmCustomers to set the SourceObject of the subform after a
[quoted text clipped - 26 lines]
how
to do one so a little code example would be very helpful.
 
Hii Shane,

I don't understand why you won't know which button the user is on - it will
be the one whose click event you are coding (unless you've got some custom
function that all buttons are calling - in which case pass the name of the
calling control, and the next control, to the function as parameters), or
which has just received focus (by a method other than clicking, such as user
tabbing to it, or my code).

The code I posted would got in a structure such as (mostly pseudo-code,
don't try to run this!!!):

Private Sub cmdFunding_Click()
or
Private Sub cmdFunding_GotFocus()
set subform recordsource
If no records
'display message asking for new funding source
Else
Me.NextCommandButton.SetFocus
End If
End Sub

You will need a code segment such as this for each of the cmdButtons; each
one will refer to the next one (in your logical scheme). If you don't know,
for any given button, which one should be next, then there's no way to do
what you want!

I also don't understand exactly what you mean by "... these cmdButtons are
nested in a Select statement ...". Are they gaining focus by the code
which is in a Select statement? If so, the code above still works, since
the GotFocus event occurs when the cmdButton receives focus via code.

If this doesn't help, then please post more details of your existing code.

HTH,

Rob

shanesullaway via AccessMonster.com said:
Thanks for the reply Rob. I wish it was as easy as that. These 10
cmdButtons are nested in a Select statement and I need this to be more
dynamic than that since I won't know for sure which one of the 10
cmdButtons
the user is on to make the focus go to the next control.

Shane

Rob said:
Me.NameOfCmdButtonToGetFocus.SetFocus

Rob
On my form 'frmCustomers', I have a subform, which is unbound. I use 10
cmdButtons on frmCustomers to set the SourceObject of the subform after
a
[quoted text clipped - 26 lines]
how
to do one so a little code example would be very helpful.
 
Hey Rob,

Each cmdButton is calling a Private Function. Within that function is a
Select Case statement that handles which control is the current one and
within in each Case is a few commands that I want to happen. I have tried
adding a variant that contains the name of the next command button so that if
a user chooses "no" on adding a new record then what I want to happen is for
focus to be set to the next cmdButton in the tab order. However, I have not
found a way to get the syntax correct. Let's say the name of the variant is
stNxButton. Within the Case part of cmdFunding (the next cmdButton is
cmdDiagnosis) I tried stNxButton = Me.cmdDignosis.SetFocus. I have tried
putting it in quotes, putting the full name instead of using Me, and etc but
have not found a way for the syntax to be accepted. Below is my function, if
it helps and you can make sense of it. I'm pretty new to designing my own
functions, so obviously I'm still not too good at it. :)

Hope this makes some sense,
Shane

Private Function SFSub()

Dim ctlCurrentControl As Control
Dim strControlName As String
Set ctlCurrentControl = Screen.ActiveControl
strControlName = ctlCurrentControl.Name

Dim stField As String
Dim stTable As String
Dim intRCount As Integer
Dim stFrmName As String
Dim stNoRec As String
Dim stCriteria As String
Dim stSSName As String
stCriteria = "CustomersID=" & Me.CustomersID

If Len(strControlName) = 0 Then
Exit Function
Else
Select Case strControlName
Case "cmdDetail"
stField = "CustomersID"
stTable = "Customers"
stNoRec = "Customer"
stFrmName = "frmCustomers"
stSSName = "frmCusCMF"
Me.lblInform.Caption = "Customer Personal Information and
Details"
Case "cmdFunding"
stField = "InsuranceID"
stTable = "Insurance"
stNoRec = "Funding"
stFrmName = "frmInsurance"
stSSName = "frmInsCMF"
Me.lblInform.Caption = "Funding Information"
Case "cmdGuardian"
stField = "GuardianID"
stTable = "Guardian"
stNoRec = "Guardian"
stFrmName = "frmGuardAdEd"
stSSName = "frmGuard"
Me.lblInform.Caption = "Guardian Personal and Detail
Information"
Case "cmdEquip"
stField = "EquipmentID"
stTable = "Equipment"
stNoRec = "EQUIPMENT"
stFrmName = "frmEquipment"
stSSName = "frmEquipOwned"
Me.lblInform.Caption = "Equipment Information and History"
Case "cmdPNotes"
MsgBox "Under Construction"
Exit Function
Case "cmdDiagnosis"
MsgBox "Under Construction"
Exit Function
Case "cmdWork"
MsgBox "Under Construction"
Exit Function
Case "cmdSchool"
MsgBox "Under Construction"
Exit Function
Case "cmdRestrictions"
MsgBox "Under Construction"
Exit Function
Case "cmdRedFlag"
MsgBox "Under Construction"
Exit Function
End Select

intRCount = Nz(DCount(stField, stTable, stCriteria), "")

If intRCount = 0 Then
If fFormattedMsgBox("No Records To Show!", _
"The " & stNoRec & " form has no records to show for
this customer. Would you like to " & _
"add a new record?", 4, _
"AMC Database System Message") = vbNo Then
'here is where I need it to move to the next cmdButton
Else
Me.subCusDet.SourceObject = stSSName
Me.subCusDet.SetFocus
DoCmd.OpenForm stFrmName, , , , acFormAdd, , Me.Name
End If
Else
Me.subCusDet.SourceObject = stSSName
End If
End If

End Function

Rob said:
Hii Shane,

I don't understand why you won't know which button the user is on - it will
be the one whose click event you are coding (unless you've got some custom
function that all buttons are calling - in which case pass the name of the
calling control, and the next control, to the function as parameters), or
which has just received focus (by a method other than clicking, such as user
tabbing to it, or my code).

The code I posted would got in a structure such as (mostly pseudo-code,
don't try to run this!!!):

Private Sub cmdFunding_Click()
or
Private Sub cmdFunding_GotFocus()
set subform recordsource
If no records
'display message asking for new funding source
Else
Me.NextCommandButton.SetFocus
End If
End Sub

You will need a code segment such as this for each of the cmdButtons; each
one will refer to the next one (in your logical scheme). If you don't know,
for any given button, which one should be next, then there's no way to do
what you want!

I also don't understand exactly what you mean by "... these cmdButtons are
nested in a Select statement ...". Are they gaining focus by the code
which is in a Select statement? If so, the code above still works, since
the GotFocus event occurs when the cmdButton receives focus via code.

If this doesn't help, then please post more details of your existing code.

HTH,

Rob
Thanks for the reply Rob. I wish it was as easy as that. These 10
cmdButtons are nested in a Select statement and I need this to be more
[quoted text clipped - 14 lines]
 
Hi Shane,

Sorry about the delay in this thread, but I suspect we're on oppposite sides
of the world ;)

Well, you're nearly there. What I suggest is:

Set another string variable for the next cmdbutton name
Dim strNextCmdButton as String

In each Case section, assign the appropriate string to this variable, eg.
Case "cmdDetail"
...
strNextCmdButton = "cmdCustomers"
...

Then in your final section, where you are processing the command, you simply
need
...
If fFormattedMsgBox("No Records To Show!"...)= vbNo Then
'move to the next cmdButton
Me.Controls(strNextCmdButton).SetFocus
Else
...

As a side point, your code can be a subroutine, rather than a function. The
key difference (in simple terms) is that a function returns a value
(usually - it can be any datatype) when it is called, whereas a subroutine
simply performs an action - as in your code.

Again, HTH,

Rob

shanesullaway via AccessMonster.com said:
Hey Rob,

Each cmdButton is calling a Private Function. Within that function is a
Select Case statement that handles which control is the current one and
within in each Case is a few commands that I want to happen. I have tried
adding a variant that contains the name of the next command button so that
if
a user chooses "no" on adding a new record then what I want to happen is
for
focus to be set to the next cmdButton in the tab order. However, I have
not
found a way to get the syntax correct. Let's say the name of the variant
is
stNxButton. Within the Case part of cmdFunding (the next cmdButton is
cmdDiagnosis) I tried stNxButton = Me.cmdDignosis.SetFocus. I have tried
putting it in quotes, putting the full name instead of using Me, and etc
but
have not found a way for the syntax to be accepted. Below is my function,
if
it helps and you can make sense of it. I'm pretty new to designing my own
functions, so obviously I'm still not too good at it. :)

Hope this makes some sense,
Shane

Private Function SFSub()

Dim ctlCurrentControl As Control
Dim strControlName As String
Set ctlCurrentControl = Screen.ActiveControl
strControlName = ctlCurrentControl.Name

Dim stField As String
Dim stTable As String
Dim intRCount As Integer
Dim stFrmName As String
Dim stNoRec As String
Dim stCriteria As String
Dim stSSName As String
stCriteria = "CustomersID=" & Me.CustomersID

If Len(strControlName) = 0 Then
Exit Function
Else
Select Case strControlName
Case "cmdDetail"
stField = "CustomersID"
stTable = "Customers"
stNoRec = "Customer"
stFrmName = "frmCustomers"
stSSName = "frmCusCMF"
Me.lblInform.Caption = "Customer Personal Information and
Details"
Case "cmdFunding"
stField = "InsuranceID"
stTable = "Insurance"
stNoRec = "Funding"
stFrmName = "frmInsurance"
stSSName = "frmInsCMF"
Me.lblInform.Caption = "Funding Information"
Case "cmdGuardian"
stField = "GuardianID"
stTable = "Guardian"
stNoRec = "Guardian"
stFrmName = "frmGuardAdEd"
stSSName = "frmGuard"
Me.lblInform.Caption = "Guardian Personal and Detail
Information"
Case "cmdEquip"
stField = "EquipmentID"
stTable = "Equipment"
stNoRec = "EQUIPMENT"
stFrmName = "frmEquipment"
stSSName = "frmEquipOwned"
Me.lblInform.Caption = "Equipment Information and History"
Case "cmdPNotes"
MsgBox "Under Construction"
Exit Function
Case "cmdDiagnosis"
MsgBox "Under Construction"
Exit Function
Case "cmdWork"
MsgBox "Under Construction"
Exit Function
Case "cmdSchool"
MsgBox "Under Construction"
Exit Function
Case "cmdRestrictions"
MsgBox "Under Construction"
Exit Function
Case "cmdRedFlag"
MsgBox "Under Construction"
Exit Function
End Select

intRCount = Nz(DCount(stField, stTable, stCriteria), "")

If intRCount = 0 Then
If fFormattedMsgBox("No Records To Show!", _
"The " & stNoRec & " form has no records to show
for
this customer. Would you like to " & _
"add a new record?", 4, _
"AMC Database System Message") = vbNo Then
'here is where I need it to move to the next cmdButton
Else
Me.subCusDet.SourceObject = stSSName
Me.subCusDet.SetFocus
DoCmd.OpenForm stFrmName, , , , acFormAdd, , Me.Name
End If
Else
Me.subCusDet.SourceObject = stSSName
End If
End If

End Function

Rob said:
Hii Shane,

I don't understand why you won't know which button the user is on - it
will
be the one whose click event you are coding (unless you've got some custom
function that all buttons are calling - in which case pass the name of the
calling control, and the next control, to the function as parameters), or
which has just received focus (by a method other than clicking, such as
user
tabbing to it, or my code).

The code I posted would got in a structure such as (mostly pseudo-code,
don't try to run this!!!):

Private Sub cmdFunding_Click()
or
Private Sub cmdFunding_GotFocus()
set subform recordsource
If no records
'display message asking for new funding source
Else
Me.NextCommandButton.SetFocus
End If
End Sub

You will need a code segment such as this for each of the cmdButtons; each
one will refer to the next one (in your logical scheme). If you don't
know,
for any given button, which one should be next, then there's no way to do
what you want!

I also don't understand exactly what you mean by "... these cmdButtons are
nested in a Select statement ...". Are they gaining focus by the code
which is in a Select statement? If so, the code above still works, since
the GotFocus event occurs when the cmdButton receives focus via code.

If this doesn't help, then please post more details of your existing code.

HTH,

Rob
Thanks for the reply Rob. I wish it was as easy as that. These 10
cmdButtons are nested in a Select statement and I need this to be more
[quoted text clipped - 14 lines]
how
to do one so a little code example would be very helpful.
 
Rob,

Thank you, thank you, thank you. You got it doing exactly what I needed it
to do. I tried so many different ways to get it to do what you did. The
only part I could never figure out was the: Me.Controls(strNextCmdButton).
SetFocus, part. You made my day. Thanks again.

Also, thanks for the information on subs vs functions. I'm new to making my
own routines and have had a hard time deciding which one to use. With your
explanation, it will make it much easier to make that decision from now on.

Thanks again,
Shane

Rob said:
Hi Shane,

Sorry about the delay in this thread, but I suspect we're on oppposite sides
of the world ;)

Well, you're nearly there. What I suggest is:

Set another string variable for the next cmdbutton name
Dim strNextCmdButton as String

In each Case section, assign the appropriate string to this variable, eg.
Case "cmdDetail"
...
strNextCmdButton = "cmdCustomers"
...

Then in your final section, where you are processing the command, you simply
need
...
If fFormattedMsgBox("No Records To Show!"...)= vbNo Then
'move to the next cmdButton
Me.Controls(strNextCmdButton).SetFocus
Else
...

As a side point, your code can be a subroutine, rather than a function. The
key difference (in simple terms) is that a function returns a value
(usually - it can be any datatype) when it is called, whereas a subroutine
simply performs an action - as in your code.

Again, HTH,

Rob
[quoted text clipped - 160 lines]
 
You're welcome :-)

Rob

shanesullaway via AccessMonster.com said:
Rob,

Thank you, thank you, thank you. You got it doing exactly what I needed
it
to do. I tried so many different ways to get it to do what you did. The
only part I could never figure out was the: Me.Controls(strNextCmdButton).
SetFocus, part. You made my day. Thanks again.

Also, thanks for the information on subs vs functions. I'm new to making
my
own routines and have had a hard time deciding which one to use. With
your
explanation, it will make it much easier to make that decision from now
on.

Thanks again,
Shane

Rob said:
Hi Shane,

Sorry about the delay in this thread, but I suspect we're on oppposite
sides
of the world ;)

Well, you're nearly there. What I suggest is:

Set another string variable for the next cmdbutton name
Dim strNextCmdButton as String

In each Case section, assign the appropriate string to this variable, eg.
Case "cmdDetail"
...
strNextCmdButton = "cmdCustomers"
...

Then in your final section, where you are processing the command, you
simply
need
...
If fFormattedMsgBox("No Records To Show!"...)= vbNo Then
'move to the next cmdButton
Me.Controls(strNextCmdButton).SetFocus
Else
...

As a side point, your code can be a subroutine, rather than a function.
The
key difference (in simple terms) is that a function returns a value
(usually - it can be any datatype) when it is called, whereas a subroutine
simply performs an action - as in your code.

Again, HTH,

Rob
[quoted text clipped - 160 lines]
how
to do one so a little code example would be very helpful.
 

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

Back
Top