PDA

View Full Version : Solved: CREATE A USERFORM INSIDE ANOTHER USERFORM



Greg
07-18-2006, 11:07 PM
Hi,

I have some Userforms through which data is entered to populate bookmarks in a Word document.

I wish to take those forms to the next level by including a command button (or whatever) to bring up another userform to perform and entirely different set of instructions on the same document.

However, I also want to be able to return to the original userform by pressing a "Back" button.

Can anyone help with this?

Greg.

ALe
07-19-2006, 02:18 AM
not sure it's what you want

lucas
07-19-2006, 07:30 AM
I like this style: see attached

Greg
07-19-2006, 05:33 PM
Thanks Lucas, I like that too and I think I can put it to very good use. Many thanks.

Greg
07-19-2006, 05:35 PM
Hi Alex,

For some reason your attachment didn't quite get through. I would be grateful if you were to try and resend it.

Greg.

lucas
07-19-2006, 06:46 PM
Hey Greg, I didn't have any trouble downloading and running Ale's attachment.....maybe it got corrupted when you downloaded it.

Greg
07-19-2006, 07:14 PM
Yes, I think you're right.

In respect of the userform you provided, how do you propose that I get the command button into an existing userform?

If I could do that I could obtain a threefold benefit. That is, I could have my existing userform from which I could bring up your userform containing the expanding slider.

I could mess around for a long time and not get the desired result.

Thanks again,

Greg,

lucas
07-20-2006, 07:04 AM
use a command button on your userform to call the sliding form. Where Userform2 is the sliding userform:

Private Sub CommandButton1_Click()
UserForm2.Show
End Sub

Download and run userform1 in Ale's example. It does exactly what your asking.

Edit: example attached

Greg
07-20-2006, 05:29 PM
Hi Lucas,

That works very well but I see that the Commandbutton belongs to a larger form that isn't visible. I expect that a minor tweak will remedy this but I am not sure where to start. Can you give some guidance on this?

Thanks again,

Greg.

lucas
07-21-2006, 04:42 AM
Hi Greg,
Hit Alt+F11 to get to the vbe and on the left side in the project explorer look for userform1 that is the expanding form. Right click on it and select view code. Look for the statement: Private Sub UserForm_Initialize() and examine the code below that statement. It sets the initial size of the form and the size and location of the button....that should get you started.

Greg
07-21-2006, 08:19 PM
Thanks Lucas,

I did in fact manage by other means to achieve the result I was looking for but I will go back and do it your way as well. It's all part of the learning process.

Greg.

fumei
07-25-2006, 01:17 PM
Of course the sliding userform is not really another userform, it is a resizing of one.

You certainly can call another userform.

However, if you need more real estate, or want to have compartmentalized structure, I highly recommend using a MultiPage. You can pack a whole whack of stuff onto one userform.

Greg
07-25-2006, 08:14 PM
Thanks fumei.

Sorry I didn't get back to you earlier but I've been a bit unwell.

However, it would appear that you have provided all the tools I need to finish my project.

Thanks again.

Greg.

fumei
07-25-2006, 09:07 PM
You are welcome. Glad to see you persisted. Hope you are well.

Greg
07-25-2006, 10:08 PM
Hi again fumei. I am well now thanks and as I am feeling better I realise that I have one further question.

In the attached code, I can clear each entry on the userform one box at a time.

This is useful but there may be instances when I would like to simply clear everything in the userform in one action. Can this be done without causing a conflict with the existing code.

In otherwords, is it possible to have choice between clearing everything and clearing the boxes one at a time and if so, would you please give me some clues as to how this would be done?

Regards,

Greg.


Option Explicit
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub CommandButton2_Click()
Dim ctl As Control
For Each ctl In Me.Controls
MsgBox ctl.Name
If TypeOf ctl Is TextBox Then
Me.Controls(ctl.Name).Text = ""
ElseIf TypeOf ctl Is CheckBox Then
Me.Controls(ctl.Name).Value = False
ElseIf TypeOf ctl Is ComboBox Then
Me.Controls(ctl.Name).ListIndex = 0
End If
Next
End Sub

Private Sub ClickToFinish_Click()
Dim varCheck
varCheck = IsNumeric(txtAmount.Text)
If varCheck = True Then
Call FillABookmark("Amount", txtAmount.Text)
Else
MsgBox "Amount does not appear to be properly numeric. " & _
"Please re-enter."
txtAmount.Text = ""
txtAmount.SetFocus
Exit Sub
End If
varCheck = IsNumeric(txtRate.Text)
If varCheck <> True Then ' is NOT numeric
If txtRate.Text = "" Then
MsgBox "Interest rate is blank. Please input a numeric entry."
txtRate.SetFocus
Exit Sub
Else
MsgBox "Interest is not numeric. Please input a numeric entry."
txtRate.Text = ""
txtRate.SetFocus
Exit Sub
End If
Else ' it IS numeric
Call FillABookmark("Rate", txtRate.Text)
Call FillABookmark("CostsOnClaim", txtCostsOnClaim.Text)
Call FillABookmark("EntryCosts", txtEntryCosts.Text)
Call FillABookmark("MoniesPaid", txtMoniesPaid.Text)
End If
Call FillABookmark("StartDate", txtStartDate.Text)
Call FillABookmark("EndDate", txtEndDate.Text)
Call FillABookmark("NumDays", DateDiff("d", txtStartDate, txtEndDate))
Call FillABookmark("DailyRate", FormatCurrency((CLng(txtAmount) * CLng(txtRate) / 100) / 365))
End Sub

Private Sub UserForm_Initialize()
Dim oBM As Word.Bookmarks
Set oBM = ActiveDocument.Bookmarks
If oBM("Amount").Range.Text <> "" Then
Me.txtAmount.Text = oBM("Amount").Range.Text
End If
If oBM("Rate").Range.Text <> "" Then
Me.txtRate.Text = oBM("Rate").Range.Text
End If
If oBM("StartDate").Range.Text <> "" Then
Me.txtStartDate.Text = oBM("StartDate").Range.Text
End If
If oBM("EndDate").Range.Text <> "" Then
Me.txtEndDate.Text = oBM("EndDate").Range.Text
End If
If oBM("CostsOnClaim").Range.Text <> "" Then
Me.txtCostsOnClaim.Text = oBM("CostsOnClaim").Range.Text
End If
If oBM("EntryCosts").Range.Text <> "" Then
Me.txtEntryCosts.Text = oBM("EntryCosts").Range.Text
End If
If oBM("MoniesPaid").Range.Text <> "" Then
Me.txtMoniesPaid.Text = oBM("MoniesPaid").Range.Text
End If
Set oBM = Nothing

End Sub

Public Sub Update()
ActiveDocument.Fields.Update
Unload Me
End Sub

Greg
07-25-2006, 10:27 PM
fumei,

In the few minutes since I sent my last message I have worked out how to clear all the boxes (although I lost the ability to clear one at a time).

I usually manage to damage some other aspect of the code but I'll get there eventually.

Greg.

fumei
07-26-2006, 10:49 AM
Greg, For Each ctl In Me.Controls
MsgBox ctl.Name
If TypeOf ctl Is TextBox Then
Me.Controls(ctl.Name).Text = "" clears out all textboxes. So I am not quite getting what you are saying. Yes, it will do it one at a time, but it does all them automatically.

fumei
07-26-2006, 10:50 AM
Although, I would remove that Msgbox ctl.Name instruction. I see no need to get the control name. I had that in for testing purposes.

Greg
07-26-2006, 05:23 PM
Hi fumei,

Yesterday's second reply advised that I had solved the problem. Also, I was wondering about your use of "Name" but it works anyway.

With your help so far, I should be able to keep developing my documents for quite a while.

Thanks again.

Greg.

geekgirlau
07-27-2006, 12:08 AM
Hi Greg,

Make sure you mark this thread as "Solved" using the Thread Tools at the top of the screen.

Greg
08-22-2007, 01:53 AM
Hi Geekgirl,

I haven't managed to solve this problem yet. Recapping, I want to numbers the paragraphs in my "Indorsement" and have them repeated in two more places (via fields) in the document.

There are two main aspects to the problem. Firstly, any attempt to format the Indorsement (e.g. indents, etc) causes the Indorsement bookmark to relocate itself outside the cell it resides in.

Secondly, I need to prevent the numbering (if a Word List is used) from increasing when the Indorsement is repeated in two fields in other parts of the document.

So that you can see what I am working with, the first page of my document is attached.

I hope you can assist,

Regards,

Greg.

fumei
08-26-2007, 10:31 PM
I haven't managed to solve this problem yet. Recapping, I want to numbers the paragraphs in my "Indorsement" and have them repeated in two more places (via fields) in the document.Huh? I would have to disagree.

Sorry, is this not a totally, completely, different question/problem/request? There has been ZERO mention of numbers, or paragraphs or fields.

Put it in another thread.