Is it possible to add a button on page one on a Userform with multipages so that it will take you to the other pages? Can sopmeone post a simple code for that?
Value property of the MultiPage Control, sets/gets the active page.
Private Sub cmdNext_Click()
Dim lCurrentPage As Long
lCurrentPage = Me.MultiPage1.Value + 1
If lCurrentPage = Me.MultiPage1.Pages.Count Then
MsgBox "You are on the last page."
Else
Me.MultiPage1.Value = lCurrentPage
End If
End Sub
Related
On Page 4 of the MultiPage form I've created a WebBrowser1 object. On Page 4 there are 2 buttons: one for msn.com, the other for google.com. If the UserForm defaults to Page 4 when opened, the buttons work fine initially, but if one of the other Pages is selected, and then the user returns to Page 4, clicking either one of the buttons causes the macro to crash with an error message 'Navigate' of object 'IWebBrowser2' failed.
Private Sub CommandButton23_Click()
Me.WebBrowser1.Navigate ("https://www.msn.com")
End Sub
Private Sub CommandButton24_Click()
Me.WebBrowser1.Navigate ("https://google.com")
End Sub
It appears that the WebBrowser needs to be "refreshed" each time Page 4 gets re/loaded. One solution is to eliminate the WebBrowser1 object from the UserForm and dynamically created a WebBrowser (wbr, below) initially, and then each time Page 4 is reselected.
Dim wbr As SHDocVw.WebBrowser
Private Sub MultiPage1_Change()
If MultiPage1.SelectedItem.Name = "Page 4" Then
Set wbr = Nothing
Set wbr = Me.MultiPage1.SelectedItem.Controls.Add("Shell.Explorer.2")
wbr.Height = 700
wbr.Left = 96
wbr.Top = 24
wbr.Width = 570
wbr.Navigate "About:Blank"
End If
End Sub
Private Sub UserForm_Initialize()
Set wbr = Me.MultiPage1.SelectedItem.Controls.Add("Shell.Explorer.2")
wbr.Height = 700
wbr.Left = 96
wbr.Top = 24
wbr.Width = 570
wbr.Navigate "About:Blank"
End Sub
I can't take credit for this solution - it was actually on another post in stackoverflow for a different problem!
Check it out:
Resizing WebBrowser Control on Excel UserForm with DPI
I need to update the Page Caption on a Tab Control in Access. I tried the following code:
Private Sub tabName_AfterUpdate()
MyTabControl.Pages(Me.MyTabControl.Value).Caption = Me.tabName
End Sub
This works well to set the Caption, but after using Tab or Enter in the field and execution of the above code I end up on the next record. What can I do to stay on the same page?
Private Sub tabName_AfterUpdate()
MyTabControl.Pages(Me.MyTabControl.Value).Caption = Me.tabName
Forms!frmMailing.Controls!MyTabControl = Me.MyTabControl.Value
End Sub
leads to the next record as well, while
Private Sub tabName_AfterUpdate()
MyTabControl.Pages(Me.MyTabControl.Value).Caption = Me.tabName
Forms!frmMailing.Controls!MyTabControl = Me.MyTabControl.Value-1
End Sub
Will jump to the previous page of the same record (as expected)!
please try following code example:
Forms("dataimport").Command8.Caption = "test"
DoEvents
command8 = control at the form "dataimport"
also the form should be opened
i have 5 pages in multipage userform.
if the next button enabled, which it can be clicked by user then it should move to next hidden page, i always got an error "Object Required" it drives me crazy.
Private Sub btnGenerate_Click()
iPageNo = MultiPage1.Value + 1
MultiPage1.Pages(iPageNo).Visible = True
MultiPage1.Value = iPageNo
End Sub
that code seems doesnt work for me, any help would be appreciate.
Thanks
Which line is causing the error when you step thru?
Ensure there are enough existing pages. Also, has the name of the MultiPage object changed?
This code below tested working (2 Pages in MultiPage1, Page2 set hidden):
Option Explicit
Private Sub CommandButton1_Click()
Dim iNextPage As Long
With Me.MultiPage1
iNextPage = .Value + 1
If iNextPage < .Pages.Count Then
.Pages(iNextPage).Visible = True
.Value = iNextPage
End If
End With
End Sub
I am working on a word document and made a command button that is suppose to hide a table. Now when I first set it, I thought I got it working I got it all styled and titled and when I clicked the button the table would disappear.
Then I saved it and closed the document but when I opened up the document I saw that the only thing that was hidden was the words inside the table, the table lines are not hidden and when I toggle the button the only thing hiding is the text.
Is there something I am doing wrong ? Here is the code in VBA
Private Sub CommandButton1_Click()
ThisDocument.Styles("HideText").Font.Hidden = Not ThisDocument.Styles("HideText").Font.Hidden
End Sub
I just want the button to toggle the text and the Table to hide every time it the button is pressed and when the document is open and closed.
Update may be on to something the table has its own style as well. should I be targeting that as well as the text within the style ? is that what is happening ?
Update #2
I was able to now hide and unhide the section of the table I wanted but it doesn't bring up the lines after I make the table visible. So is there a way to get the table grid to show up with the click of the button?
here is what I have so far.
Private Sub CommandButton1_Click()
ThisDocument.Styles("HideText").Font.Hidden = Not ThisDocument.Styles("HideText").Font.Hidden
'Table Grid
Dim s As Style
Dim An As Integer
An = 0
If An = 0 Then
For Each s In ActiveDocument.Styles
If s.Type = wdStyleTypeTable Then
If s.NameLocal = "Table Grid" Then
Debug.Print (s.NameLocal)
s.Visibility = False
s.UnhideWhenUsed = False
Call s.Delete
End If
End If
Next
An = 1
End If
If An = 1 Then
For Each s In ActiveDocument.Styles
If s.Type = wdStyleTypeTable Then
If s.NameLocal = "Table Grid" Then
Debug.Print (s.NameLocal)
s.Visibility = True
s.UnhideWhenUsed = True
Call s.Delete
End If
End If
Next
An = 0
End If
End Sub
I'd approach this by hiding the font of the table (as below) rather than attempting to hide a specific font style which you're using within the table.
You could try something along the lines of:
Public sub CommandButton1_Click()
With ActiveDocument.Tables(1).Range.Font
.Hidden = Not .Hidden
End With
End Sub
I have a custom template that I built in Word.
I used Content controls for certain fill-able fields and used 'Restrict editing' - 'No changes' with exceptions (the content controls) to protect it.
After the user fills out the content control information, they click a "Reset" button to start over. The code associated with this button is below.
Question is: How do I re-protect the doc with the original protection parameters I put in place?
Thank you for your help!
JP
Private Sub CommandButton21_Click()
ActiveDocument.Unprotect ("Word")
Dim oCC As ContentControl
x = 1
For Each oCC In ActiveDocument.ContentControls
Count = x
If Count > 0 Then
oCC.Range.Text = ""
End If
x = x + 1
Next oCC
ActiveDocument.Protect wdNoProtection, , "Word"
End Sub