need help understanding syntax for adding a page to multipage

G

GregJG

this is the syntax the help page says to add a page to a multipage

Set Object = object.Add( [ Name [, Caption [, index]]])

so I created a commandbutton, outside of the multipage control an
coded as;

private sub commandbutton1_click()
set multipage1 = page.add( [page3 [, Page3 [, 2]]])
end sub

but I am receiving an error

"invalid use of property" and Multipage1 is highlighted.

I have checked the name and it is correct.


any help
 
B

Bob Phillips

Greg,

This works for me

Private Sub CommandButton1_Click()
Dim myObj As Object

Set myObj = MultiPage1.Pages.Add("Page3")
End Sub


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
G

GregJG

Thanks Bob!!

I have spent the last 3 hours trying to figure this out.

ms help is pretty vagu
 
G

GregJG

This is a new project for me, have never messed with multipage before.

i am going to be adding a commandbutton that will add a sheet for ever
trip that is made to a job location.

ie; trip1, trip2 ect..

so, in theory I want to do an If_Then statement

Private Sub CommandButton1_Click()
Dim myObj As Object
if Multipage1.Pages("trip1") = true then
Set myObj = MultiPage1.Pages.Add("Trip2")
end if
End Sub


do ya think something like that will work
 
B

Bob Phillips

The problem that I find with help is that you drill down into a method for
the object you are interested in, and then find it has concatenated many
topics, and gives an example that isn't applicable to your situation.

C'est la vie.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
B

Bob Phillips

Greg,

You will need to test in a loop for all of them using that approach, but
it's easier than that

Private Sub CommandButton1_Click()
Dim myObj As Object

With MultiPage1
Set myObj = .Pages.Add("Trip" & .Pages.Count + 1)
End With
End Sub

But you have a basic design flaw here. Whilst the form is up, and you add
new pages, all will work okay. However, these controls are added at runtime,
and will disappear when you close the form down, and will not exist the next
time you open the form, you will just have the design pages.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
G

GregJG

it will still disappear even though I use a savebutton

thisworkbook.saveas.filename: =

and having

Private Sub Workbook_Open()
userform1.show
End Sub

that when I reopen the workbook, all of the tabs wouldn't show?

perhaps doing something like

Private Sub Workbook_open()
userform1.show
call commandbuttons
end sub

?
 
G

GregJG

right now, i am working on a printpreview problem, but as soon as
finish this, I will be ready for the multipage project.

I really appreciate your posts!
 
B

Bob Phillips

Greg,

Yes it will disappear because you are only adding the controls to the form
in memory, not the form in the workbook.

The only way around it that I can see is to save the in formation on a
worksheet when the form terminates, and then when you show it, check that
worksheet and re-create it. Something like this, but firts delete the
multipage from your userform, as it also gets created dynamically with this
approach

Private Sub UserForm_Terminate()
Dim i As Long
Dim pge
Dim oPages As MultiPage

On Error GoTo ut_exit
Set oPages = Me.Controls("TripsPages")
With Worksheets("Trips")
For i = 0 To oPages.Count - 1
Cells(i + 1, "A").Value = oPages(i).Caption
Next i
End With

ut_exit:
End Sub

When you open the form, use code like this

Private Sub UserForm_Initialize()
Dim oPages As MultiPage
Dim oPage As Page
Dim oSaved As Worksheet
Dim i As Long
Dim cRows As Long

Set oPages = Me.Controls.Add("Forms.Multipage.1")
With oPages
For Each oPage In .Pages
.Pages.Remove oPage.Caption
Next oPage
.Name = "TripsPages"
.Left = 20
.Top = 20
Set oSaved = Worksheets("Trips")
cRows = oSaved.Cells(Rows.Count, "A").End(xlUp).Row
If cRows = 1 And oSaved.Range("A1") = "" Then
Exit Sub
End If
For i = 1 To cRows
Set oPage = .Add("Trip" & i)
Next
End With

End Sub

and finally, you need to amend the commandbutton code to

Private Sub CommandButton1_Click()
Dim opage As Page

With Me.Controls("TripsPages")
Set opage = .Pages.Add("Trip" & .Pages.Count + 1)
End With
End Sub


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
G

GregJG

Hey Bob, I'm back and ready to start on this multipage thing.

this is what I was hoping to do.

create a workbook1 that, when opened, automatically opens userform1 s
the user only sees the form (this I have done in the past). When th
user inputs information on the form and hits the save button, a ne
workbook2.sheet1 is created with each box value from the userfor
placed in certain cells.

i.e.: the first page on the form has 102 checkboxes, textboxes an
comboboxes. when the command button to save is clicked a new workboo
is created and each box value is placed in column A lines 1 thru 102
and the workbook is saved with a specific name.

on my userform1, create a combobox, listbox or perhaps a filedialo
box (I have never tried creating a file dialog box in vba).
that show a list of the workbook2's and when the file is clicked, i
opens the workbook2, fills in the 102 boxes on the userform1 with th
info in the 102 cells , then the workbook2 is closed.

the reason i want to try this is to save HD space. the userform file i
1mb, where as the info needed for the form is only 4kb. that way i a
only adding 4kb to my harddrive instead of the 1mb.

make sense? do ya think there is an easier way? I would be intereste
in hearing any opinion ya have.

Thanks for your time
 

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

Top