Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 440
Default User form question

Two (of many) text boxes on a user form have control sources on the
spreadsheet hidden behind. These controls are =TODAY() and =USERNAME(). These
text boxes are locked.

The problem is that when the command button on the form is clicked to move
input data on the form to the spreadsheet behind, the formulae stated above
are removed leaving the date in one text box while the other is empty. How
can I adapt the vba to copy the data in TextBox1 and TextBox2 rather than
removing it?

Thanks for any ideas on this.

Jock
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default User form question

You can have a value or a formula in a cell. The textbox will put a value in
the cell and remove the formula.

Break the controlsource and manage the updating of the cell with code. You
can program the content of the cell as you wish.

--
regards,
Tom Ogilvy


"Jock" wrote:

Two (of many) text boxes on a user form have control sources on the
spreadsheet hidden behind. These controls are =TODAY() and =USERNAME(). These
text boxes are locked.

The problem is that when the command button on the form is clicked to move
input data on the form to the spreadsheet behind, the formulae stated above
are removed leaving the date in one text box while the other is empty. How
can I adapt the vba to copy the data in TextBox1 and TextBox2 rather than
removing it?

Thanks for any ideas on this.

Jock

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 440
Default User form question

Ahhh. Right. Not sure how to approach that. Tbh, I have done it this way as I
can't get the date and usernames to appear in those text boxes when the form
is first opened; once one form full of data has been moved, code fills in
these two textboxes ok, it's just the very first one.

Thanks though Tom, I appreciate the reply.

Jock


"Tom Ogilvy" wrote:

You can have a value or a formula in a cell. The textbox will put a value in
the cell and remove the formula.

Break the controlsource and manage the updating of the cell with code. You
can program the content of the cell as you wish.

--
regards,
Tom Ogilvy


"Jock" wrote:

Two (of many) text boxes on a user form have control sources on the
spreadsheet hidden behind. These controls are =TODAY() and =USERNAME(). These
text boxes are locked.

The problem is that when the command button on the form is clicked to move
input data on the form to the spreadsheet behind, the formulae stated above
are removed leaving the date in one text box while the other is empty. How
can I adapt the vba to copy the data in TextBox1 and TextBox2 rather than
removing it?

Thanks for any ideas on this.

Jock

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default User form question

Dim bBlockEvents as Boolean
Private Sub Userform_Initialize
bBlockEvents = True
me.Textbox1.Value = Application.UserName
me.Textbox2.Value = Worksheets("sheet1").Range("B9").Text
bBlockEvents = False
End Sub

Private Sub Textbox1_Change()
if bBlockEvents then exit sub

' code to update the cells
End Sub

and so forth.

--
regards,
Tom Ogilvy


--
Regards,
Tom Ogilvy



"Jock" wrote:

Ahhh. Right. Not sure how to approach that. Tbh, I have done it this way as I
can't get the date and usernames to appear in those text boxes when the form
is first opened; once one form full of data has been moved, code fills in
these two textboxes ok, it's just the very first one.

Thanks though Tom, I appreciate the reply.

Jock


"Tom Ogilvy" wrote:

You can have a value or a formula in a cell. The textbox will put a value in
the cell and remove the formula.

Break the controlsource and manage the updating of the cell with code. You
can program the content of the cell as you wish.

--
regards,
Tom Ogilvy


"Jock" wrote:

Two (of many) text boxes on a user form have control sources on the
spreadsheet hidden behind. These controls are =TODAY() and =USERNAME(). These
text boxes are locked.

The problem is that when the command button on the form is clicked to move
input data on the form to the spreadsheet behind, the formulae stated above
are removed leaving the date in one text box while the other is empty. How
can I adapt the vba to copy the data in TextBox1 and TextBox2 rather than
removing it?

Thanks for any ideas on this.

Jock

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 440
Default User form question

Thanks Tom.
Just to clarify, is this to populate the two empty fields upon opening:
adding it (somehow) to this code?
Private Sub Workbook_Open()
UserForm1.Show
End Sub

or copying text from the text boxes and not the formlae behind them when
command button is clicked, invoking this:

Private Sub CommandButton1_Click()
Dim LastRow As Object

Set LastRow = Sheet1.Range("a200").End(xlUp)

LastRow.Offset(1, 0).Value = TextBox1.Text
LastRow.Offset(1, 1).Value = TextBox2.Text
LastRow.Offset(1, 2).Value = TextBox3.Text
LastRow.Offset(1, 3).Value = TextBox4.Text
LastRow.Offset(1, 4).Value = TextBox5.Text
LastRow.Offset(1, 5).Value = TextBox6.Text
LastRow.Offset(1, 6).Value = TextBox7.Text
LastRow.Offset(1, 7).Value = TextBox8.Text

If vbYes Then
TextBox1.Text = Now()
TextBox2.Text = UserName()
TextBox3.Text = ""
TextBox4.Text = "supplier"
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
TextBox9.Text = ""

Else
Unload Me
End If

End Sub


Thanks again Tom

regards,

Jock


"Tom Ogilvy" wrote:

Dim bBlockEvents as Boolean
Private Sub Userform_Initialize
bBlockEvents = True
me.Textbox1.Value = Application.UserName
me.Textbox2.Value = Worksheets("sheet1").Range("B9").Text
bBlockEvents = False
End Sub

Private Sub Textbox1_Change()
if bBlockEvents then exit sub

' code to update the cells
End Sub

and so forth.

--
regards,
Tom Ogilvy


--
Regards,
Tom Ogilvy



"Jock" wrote:

Ahhh. Right. Not sure how to approach that. Tbh, I have done it this way as I
can't get the date and usernames to appear in those text boxes when the form
is first opened; once one form full of data has been moved, code fills in
these two textboxes ok, it's just the very first one.

Thanks though Tom, I appreciate the reply.

Jock


"Tom Ogilvy" wrote:

You can have a value or a formula in a cell. The textbox will put a value in
the cell and remove the formula.

Break the controlsource and manage the updating of the cell with code. You
can program the content of the cell as you wish.

--
regards,
Tom Ogilvy


"Jock" wrote:

Two (of many) text boxes on a user form have control sources on the
spreadsheet hidden behind. These controls are =TODAY() and =USERNAME(). These
text boxes are locked.

The problem is that when the command button on the form is clicked to move
input data on the form to the spreadsheet behind, the formulae stated above
are removed leaving the date in one text box while the other is empty. How
can I adapt the vba to copy the data in TextBox1 and TextBox2 rather than
removing it?

Thanks for any ideas on this.

Jock



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default User form question

That really doesn't clarify anything for me.

this to populate the two empty fields upon opening


solution provided. If you want to populate cells, then adjust the code to
populate the cells or do it in the workbook open event.


or copying text from the text boxes and not the formlae behind them when
is meaningless to me. If you have a controlsource set, the cells are
updated with the entries from the textboxes. If not set, then your code
would update the cells.

Any formulas in the cells would be overwritten in either context.

--
regards,
Tom Ogilvy






"Jock" wrote:

Thanks Tom.
Just to clarify, is this to populate the two empty fields upon opening:
adding it (somehow) to this code?
Private Sub Workbook_Open()
UserForm1.Show
End Sub

or copying text from the text boxes and not the formlae behind them when
command button is clicked, invoking this:

Private Sub CommandButton1_Click()
Dim LastRow As Object

Set LastRow = Sheet1.Range("a200").End(xlUp)

LastRow.Offset(1, 0).Value = TextBox1.Text
LastRow.Offset(1, 1).Value = TextBox2.Text
LastRow.Offset(1, 2).Value = TextBox3.Text
LastRow.Offset(1, 3).Value = TextBox4.Text
LastRow.Offset(1, 4).Value = TextBox5.Text
LastRow.Offset(1, 5).Value = TextBox6.Text
LastRow.Offset(1, 6).Value = TextBox7.Text
LastRow.Offset(1, 7).Value = TextBox8.Text

If vbYes Then
TextBox1.Text = Now()
TextBox2.Text = UserName()
TextBox3.Text = ""
TextBox4.Text = "supplier"
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
TextBox9.Text = ""

Else
Unload Me
End If

End Sub


Thanks again Tom

regards,

Jock


"Tom Ogilvy" wrote:

Dim bBlockEvents as Boolean
Private Sub Userform_Initialize
bBlockEvents = True
me.Textbox1.Value = Application.UserName
me.Textbox2.Value = Worksheets("sheet1").Range("B9").Text
bBlockEvents = False
End Sub

Private Sub Textbox1_Change()
if bBlockEvents then exit sub

' code to update the cells
End Sub

and so forth.

--
regards,
Tom Ogilvy


--
Regards,
Tom Ogilvy



"Jock" wrote:

Ahhh. Right. Not sure how to approach that. Tbh, I have done it this way as I
can't get the date and usernames to appear in those text boxes when the form
is first opened; once one form full of data has been moved, code fills in
these two textboxes ok, it's just the very first one.

Thanks though Tom, I appreciate the reply.

Jock


"Tom Ogilvy" wrote:

You can have a value or a formula in a cell. The textbox will put a value in
the cell and remove the formula.

Break the controlsource and manage the updating of the cell with code. You
can program the content of the cell as you wish.

--
regards,
Tom Ogilvy


"Jock" wrote:

Two (of many) text boxes on a user form have control sources on the
spreadsheet hidden behind. These controls are =TODAY() and =USERNAME(). These
text boxes are locked.

The problem is that when the command button on the form is clicked to move
input data on the form to the spreadsheet behind, the formulae stated above
are removed leaving the date in one text box while the other is empty. How
can I adapt the vba to copy the data in TextBox1 and TextBox2 rather than
removing it?

Thanks for any ideas on this.

Jock

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
User Form question ah Excel Discussion (Misc queries) 1 November 5th 07 10:40 AM
user form question Gary Keramidas Excel Programming 1 October 29th 05 05:15 AM
User Form Question Steve Klenner Excel Programming 2 June 9th 05 10:07 PM
User form question nath Excel Programming 1 May 20th 04 04:41 AM
User Form Question Ray Batig Excel Programming 2 January 17th 04 03:28 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"