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.