opening second userform with button click on first userform

littlepete

Well-known Member
Joined
Mar 26, 2015
Messages
503
Office Version
  1. 365
Platform
  1. Windows
Hello :)

My first userform shows all available data from a person (names, addresses, birth and other data,...)
the button "show text" on that first userform should open a smaller userform on top of the first one,
and put the contents of column F in the active row in it (it is a written full text with all data in it:
i stead of " birth: 19.04.1961" it will say: "... was born on 19 april 1961 in ... "

i have tried button.change ; .initialize ; .text ; .value ; userform .initialize ; ...

I guess the vba can be very short:

showtext.show
dim thisrow as long
ufuserform.pfnaam.Text = Sheets("gegevens").Range("ak" & dezerij).Value

but nothing happens...
after clicking the showtext button on the first userform, it shows the second userform : perfect!
but it does not fill the one and only textbutton to show that text...

as always, the problem is: where should i put the code, and what?

have fun creating ;) !
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
If these are modal userforms (which is the default) then once the first form executes

VBA Code:
showtext.show

then it will not execute any more code until the second form is closed.

In your second userform, create a sub like this:

VBA Code:
Public Sub UserForm_Activate()
   ufuserform.pfnaam.Text = Sheets("gegevens").Range("ak" & dezerij).Value
End Sub
 
Upvote 0
hello and thanks for the help ;) !

this is what i have sofar:

first userform ufpersonenfiche has among others "show text" button. (working well)
second userform uftoontekst has only one button "close userform". (working well)
there is only one textbutton on that second userform : ttvolletekst (full text). (that stays empty)

in the second userform i now have:
VBA Code:
Private Sub uftoontekst_activate()
uftoontekst.ttvolletekst.Text = Sheets("gegevens").Range("f" & dezerij).Value
End Sub

what should i add or change to let the text of column F appear in the textbox?
(wordwrap is on, multiline is on, font is black on blue background,
the second userform is put exactly on top of the first one, except for the titlebar of u.f. one...
 
Upvote 0
You have to use this exactly, no matter what the name of your userform is.

VBA Code:
Public Sub UserForm_Activate()
 
Upvote 0
You have to use this exactly, no matter what the name of your userform is.

VBA Code:
Public Sub UserForm_Activate()
ohhh !!! I DID NOT know that !!! thank you ...
vba makes me angry many times though... being patient is not easy...

now, that second line is turning yellow... i already tried adding userform1.unload and without...
vba is fun but problems take too much time :( ... thanks for helping !!!

to be clear:
i open first userform, then i click showdata button to view all person's data
then on userform 1 i click show text button, and on top of userform 1 i see userform 2 nicely placed...
and without clicking i should see the data in full text from column F in the database placed in the textbutton
on that userform 2...

but it still doesnt show...
 
Upvote 0
PROBLEM SOLVED !!!

i had this:

Private Sub uftoontekst_activate()
uftoontekst.ttvolletekst.Text = Sheets("gegevens").Range("f" & dezerij).Value
End Sub

i forgot to define what dezerij (thisrow) is !!!
i added dim dezerij as long some time ago BUT i forgot to tell what it is ...


VBA Code:
Private Sub userform_activate()
Dim dezerij As Long
dezerij = ActiveCell.Row
uftoontekst.ttvolletekst.Text = Sheets("gegevens").Range("f" & dezerij).Value
End Sub

the whole time i was looking on the wrong place... now it works finally...

thank you very much for helping, i again learned a few things :) !!!
 
Upvote 0
Solution
For UserForm and Worksheet modules, the event handlers always start with UserForm_ and Worksheet_, not the name of the actual userform or worksheet

VBA Code:
Private Sub UserForm_Activate
Private Sub UserForm_Initialize
Private Sub UserForm_Click

Private Sub Worksheet_Change
Private Sub Worksheet_SelectionChange
Private Sub Worksheet_BeforeDoubleClick

and so on
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,595
Members
449,089
Latest member
Motoracer88

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