Entering data into two text boxes using one command button

  • Thread starter Thread starter Charlie Chalk
  • Start date Start date
C

Charlie Chalk

Hi

I have the following code in a workbook:


Code:
--------------------

'takes data from cell A45 (Phase Instructions worksheet) and puts into textbox
Private Sub CreateEmail_Click()
On Error GoTo ErrHandler
Dim strText As String
For Each r In Sheets("Phase instructions").Range("A45").Rows
strText = ""
For Each c In r.Cells
strText = strText & c.Value
Next c
EmailSubject = EmailSubject & strText & vbCrLf
Next r
ExitPoint:
Exit Sub

ErrHandler:
If Err.Number = 999 Then
Resume Next
Else
MsgBox "Incorrect data for this printer, please re-enter", vbCritical, "PRINTER DATA ERROR"
Resume ExitPoint
End If
End Sub

--------------------


I would like for the button to fill another text box (called EmailBody)
at the same time, but I don't know how to get it to fill the two boxes.


Can anyone please advise me on what I need to change in the above code
to get this to work?

Thanks very much

CC
 
Charlie, I can see where you build your strings, strText then
EmailSubject but I cannot see where you are populating any textboxes.

The code to fill two texboxes withthe same variable would be something
like;
textbox1.value = EmailSubject
textbox2.value = EmailSubject

In your line
For Each r In Sheets("Phase instructions").Range("A45").Rows

This would only contain 1 row and therefore does not need a loop,
unless I am missing something.
Also, stepping through the code with F8
For Each c In r.Cells
shows that c contains the full value of Cells and as you have only
selected "A45" no loops are executed at all. The resultant value of
strText and then EmailSubject are the same as cell A45.
 

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

Back
Top