ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Problem using UserForm in Macro (https://www.excelbanter.com/excel-programming/273900-re-problem-using-userform-macro.html)

Bill Lunney

Problem using UserForm in Macro
 
You have your commands the wrong way round. Something like:

Public Sub test()
With UserForm1
.TextBox1.Text = "hello"
.Show
End With
End Sub

would work. Problem is your showing the form, execution jumps to it (even
if it has no code) and only returns to the line setting the text when it is
closed (assuming it's a modal form).


--
Regards,


Bill Lunney
www.billlunney.com

"Terence" wrote in message
...
Hi,

I am writing a macro with a button on the worksheet. When
the button is clicked, the userform pops up and the data
of the recordset is displayed on the textbox of the form.

e.g.

Private Sub cmdButton_Click()
:
:
frmTest.Show
frmTest.txtbox1.Value = rst.Fields("testing")
End Sub


However, the screen pops up but the textbox remains empty.
Then I close the form and press the button again, the
screen pops up but this time the value is shown on the
textbox. Does anyone knows why?
Thanks a lot.

Terence





All times are GMT +1. The time now is 12:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com