Mousedown event taking me back to Page1 of MultiPage Userform

sspatriots

Well-known Member
Joined
Nov 22, 2011
Messages
585
Office Version
  1. 365
Platform
  1. Windows
I have the Mousedown event below that clicks a calendar image to force a date from a datepicker into a textbox on Page2 of my MultiPage UserForm. The problem I'm having is when it puts it puts the date in that field, the UserForm automatically jumps back to Page1 and takes me out of Page2. The reason I have the code the way it is right now is because the way it is set up, it puts a vertical scroll bar in my "txtWeeklyStatusSummary" text box that is at the bottom of both Pages of the UserForm. It presets the scrollbar to the top of the textboxes like I want them to.

What can I do to the code below to make it such that when I use the Mousedown event my UserForm doesn't switch back to Page1. I have two of these calendar images for 2 different textboxes that get date entries that way. If someone can help me with one, I think I can fix the other.


Thanks, SS


VBA Code:
Private Sub Image18_Mousedown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    ctrlName_SetDate = "txtCUSTPODate": FormName_SetDate = Me.Name: PopDatePickerX.Show
End Sub



VBA Code:
Private Sub MultiPage1_Change()

Dim currentPage As String
currentPage = MultiPage1.SelectedItem.Name

If currentPage = "Page1" Then

    With Me.txtWeeklyStatusSummary
        .SetFocus
        .CurLine = 0
    End With


End If

If currentPage = "Page2" Then

    With Me.txtWeeklyStatusSummary2
        .SetFocus
        .CurLine = 0
    End With

    With Me.cboJobType
        .SetFocus
    End With


End If

End Sub


This is at the end of my UserForm Activate code
VBA Code:
    Me.MultiPage1.Value = 1                    'SPS, 08/10/22
    Me.MultiPage1.Value = 0                    'SPS, 08/10/22
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Managed to get this to work after a weekend of messing with placement of some code I found online...


Ended up adding this line of code to the top of my Form Code:
VBA Code:
Public ChangedOnce As Boolean



Option Explicit Code with added line:
VBA Code:
Option Explicit

Private Declare PtrSafe Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwflags As Long, ByVal dwExtraInfo As Long)
Private Declare PtrSafe Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long

Private Const WM_CLOSE = &H10
Private Const VK_MENU = &H12
Private Const VK_SNAPSHOT = &H2C
Private Const KEYEVENTF_KEYUP = &H2

Public ChangedOnce As Boolean


Then added the following to my Private Sub UserForm_Activate() code just before the end:
VBA Code:
    If ChangedOnce Then Exit Sub
    ChangedOnce = True


This part of the Private Sub UserForm_Activate() code now looks like this:
VBA Code:
    If ChangedOnce Then Exit Sub
    ChangedOnce = True
    
   
    Me.MultiPage1.Value = 1                    'SPS, 08/10/22
    Me.MultiPage1.Value = 0                    'SPS, 08/10/22

I hope this helps someone else with a similar problem down the road. Thanks, SS
 
Upvote 0
Solution

Forum statistics

Threads
1,223,888
Messages
6,175,203
Members
452,617
Latest member
Narendra Babu D

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top