S
SaeOngJeeMa
Hi, I have a ComboBox (cboAcctsJmpToCntct) in the first tab of a 4-tab
multipage in a UserForm (ufrmControls). When there is an updated value
entered into that combobox I want Excel open a different tab on the
multipage. See code below. The AfterUpdate event of the combobox launches a
public sub, jumptoNewWshtAndRecord . The problem is that when the sub
executes is doesn't execute the following line of code (no error, it just
basically doesn't do anything when this line executes)
ufrmControls.MultiPage1.Value = 1
I have tried executing this line of code from the Immediate Window when no
subs or functions are running and it opens up the second tab fine. So my
guess is there's a sequence problem in my code- Since, at the time my sub
executes the line of code, I'm currently running code launched by an event in
the first tab maybe it's not letting me open the second tab. It's a Catch-22
because, to my knowledge, there aren't any events outside the first tab that
I can use to trigger the execution of my multipage value change to 1 (second
tab). Any advice would be greatly appreciated. Thanks.
Best Regards,
Dean
************************************************************
'***********Combo Box In MultiPage1 pgeAccts (first tab, Value=0)*********
Private Sub cboAcctsJmpToCntct_AfterUpdate()
If IsNull(ufrmControls.cboAcctsJmpToCntct.Value) Then
'do nothing
Else
Call jumptoNewWshtAndRecord(2, ufrmControls.cboAcctsJmpToCntct.Value)
End If
End Sub
'***********Sub in one of my Public Modules******************
Public Sub jumptoNewWshtAndRecord(bytWorksheet As Byte, lngRefNum As Long)
On Error GoTo Err_jumptoNewWshtAndRecord
Dim lngLastRow As Long
Dim lngJ01 As Long
Dim bytFoundFlag As Byte
'find the last row in the jump to worksheet
lngLastRow = Worksheets(bytWorksheet).Range("A65536").End(xlUp).Row
'loop through the RefNum values from the top row down looking for a match
bytFoundFlag = 0
lngJ01 = 3
Do While ((bytFoundFlag = 0) And (lngJ01 <= lngLastRow))
If Worksheets(bytWorksheet).Cells(lngJ01, 1).Value = lngRefNum Then
bytFoundFlag = 1
Worksheets(bytWorksheet).Select
Worksheets(bytWorksheet).Cells(lngJ01, 1).Select
Worksheets(bytWorksheet).Activate
Select Case bytWorksheet
Case 1 'Accounts
ufrmControls.MultiPage1.Value = 0
Case 2 'Contacts
ufrmControls.MultiPage1.Value = 1
Case 3 'Opportunities
ufrmControls.MultiPage1.Value = 2
Case 4 'Actions
ufrmControls.MultiPage1.Value = 3
End Select
End If
lngJ01 = lngJ01 + 1
Loop
Exit_jumptoNewWshtAndRecord:
Exit Sub
Err_jumptoNewWshtAndRecord:
MsgBox "Sub jumptoNewWshtAndRecord " & Err.Description
Resume Exit_jumptoNewWshtAndRecord
End Sub
************************************************************
multipage in a UserForm (ufrmControls). When there is an updated value
entered into that combobox I want Excel open a different tab on the
multipage. See code below. The AfterUpdate event of the combobox launches a
public sub, jumptoNewWshtAndRecord . The problem is that when the sub
executes is doesn't execute the following line of code (no error, it just
basically doesn't do anything when this line executes)
ufrmControls.MultiPage1.Value = 1
I have tried executing this line of code from the Immediate Window when no
subs or functions are running and it opens up the second tab fine. So my
guess is there's a sequence problem in my code- Since, at the time my sub
executes the line of code, I'm currently running code launched by an event in
the first tab maybe it's not letting me open the second tab. It's a Catch-22
because, to my knowledge, there aren't any events outside the first tab that
I can use to trigger the execution of my multipage value change to 1 (second
tab). Any advice would be greatly appreciated. Thanks.
Best Regards,
Dean
************************************************************
'***********Combo Box In MultiPage1 pgeAccts (first tab, Value=0)*********
Private Sub cboAcctsJmpToCntct_AfterUpdate()
If IsNull(ufrmControls.cboAcctsJmpToCntct.Value) Then
'do nothing
Else
Call jumptoNewWshtAndRecord(2, ufrmControls.cboAcctsJmpToCntct.Value)
End If
End Sub
'***********Sub in one of my Public Modules******************
Public Sub jumptoNewWshtAndRecord(bytWorksheet As Byte, lngRefNum As Long)
On Error GoTo Err_jumptoNewWshtAndRecord
Dim lngLastRow As Long
Dim lngJ01 As Long
Dim bytFoundFlag As Byte
'find the last row in the jump to worksheet
lngLastRow = Worksheets(bytWorksheet).Range("A65536").End(xlUp).Row
'loop through the RefNum values from the top row down looking for a match
bytFoundFlag = 0
lngJ01 = 3
Do While ((bytFoundFlag = 0) And (lngJ01 <= lngLastRow))
If Worksheets(bytWorksheet).Cells(lngJ01, 1).Value = lngRefNum Then
bytFoundFlag = 1
Worksheets(bytWorksheet).Select
Worksheets(bytWorksheet).Cells(lngJ01, 1).Select
Worksheets(bytWorksheet).Activate
Select Case bytWorksheet
Case 1 'Accounts
ufrmControls.MultiPage1.Value = 0
Case 2 'Contacts
ufrmControls.MultiPage1.Value = 1
Case 3 'Opportunities
ufrmControls.MultiPage1.Value = 2
Case 4 'Actions
ufrmControls.MultiPage1.Value = 3
End Select
End If
lngJ01 = lngJ01 + 1
Loop
Exit_jumptoNewWshtAndRecord:
Exit Sub
Err_jumptoNewWshtAndRecord:
MsgBox "Sub jumptoNewWshtAndRecord " & Err.Description
Resume Exit_jumptoNewWshtAndRecord
End Sub
************************************************************