String manipulation and forms
O so I'm a Noob, and I hope someone has a simple answer for me. I Have a 5 Form project, and 4 of the 5 forms have textboxes that I need to store values in. I can Switch between forms and the code creates a new instance of the form each time it is brought back into focus. the ultimate goal is to have the text remain visible when switching back and forth between forms and at the end of the program copy all the text to the clipboard in the order that the text was entered with a newline character between textboxes.
(Form 1)
Code:
Dim f2 As New UserForm2
Dim Txt1Frm1 As String
Dim Txt2Frm1 As String
Dim Txt3Frm1 As String
Dim Txt4Frm1 As String
Dim Txt5Frm1 As String
Private Sub CommandButton1_Click()
f2.Show
Me.Hide
End Sub
Public Sub T1F1_Change()
Txt1Frm1 = T1F1.Text
End Sub
Private Sub T2F1_Change()
Txt2Frm1 = T2F1.Text
End Sub
Private Sub T3F1_Change()
Txt3Frm1 = T3F1.Text
End Sub
Private Sub T4F1_Change()
Txt4Frm1 = T4F1.Text
End Sub
Private Sub T5F1_Change()
Txt5Frm1 = T5F1.Text
End Sub
(Form 2)
Code:
Dim f3 As New UserForm3
Dim f1 As New UserForm1
Dim Txt1Frm2 As String
Dim Txt2Frm2 As String
Dim Txt3Frm2 As String
Private Sub T1F2_Change()
End Sub
Private Sub T2F2_Change()
End Sub
Private Sub T3F2_Change()
End Sub
Private Sub CommandButton1_Click()
Shell "C:\Program Files\Internet Explorer\iexplore.exe http://www.Somewhere.com", vbNormalFocus
End Sub
Private Sub CommandButton2_Click()
f3.Show
Me.Hide
End Sub
Public Sub CommandButton3_Click()
f1.Show
Me.Hide
End Sub
(Form 3)
Code:
Dim f2 As New UserForm2
Dim f4 As New UserForm4
Dim Txt1Frm3 As String
Dim Txt2Frm3 As String
Dim Txt3Frm3 As String
Dim Txt4Frm3 As String
Dim Txt5Frm3 As String
Private Sub CommandButton1_Click()
f4.Show
Me.Hide
End Sub
Private Sub CommandButton2_Click()
Shell "C:\Program Files\Internet Explorer\iexplore.exe http://www.Somewhere.com", vbNormalFocus
End Sub
Private Sub CommandButton3_Click()
f2.Show
Me.Hide
End Sub
Private Sub T1F3_Change()
End Sub
Private Sub T2F3_Change()
End Sub
Private Sub T3F3_Change()
End Sub
Private Sub T4F3_Change()
End Sub
Private Sub T5F3_Change()
End Sub
(Form 4)
Code:
Dim f3 As New UserForm3
Dim f5 As New UserForm5
Dim Txt1Frm4 As String
Private Sub CommandButton1_Click()
f5.Show
Me.Hide
End Sub
Private Sub CommandButton2_Click()
f3.Show
Me.Hide
End Sub
Private Sub T1F4_Change()
End Sub
(Form 5)
Code:
Private Sub CommandButton1_Click()
Clipboard.Clear (This isn't working)
Clipboard.SetText T1F1.Text & vbCrLf
Clipboard.SetText T2F1.Text & vbCrLf
Clipboard.SetText T3F1.Text & vbCrLf
Clipboard.SetText T4F1.Text & vbCrLf
Clipboard.SetText T5F1.Text & vbCrLf
Clipboard.SetText T1F2.Text & vbCrLf
Clipboard.SetText T2F2.Text & vbCrLf
Clipboard.SetText T3F2.Text & vbCrLf
Clipboard.SetText T1F3.Text & vbCrLf
Clipboard.SetText T2F3.Text & vbCrLf
Clipboard.SetText T3F3.Text & vbCrLf
Clipboard.SetText T4F3.Text & vbCrLf
Clipboard.SetText T5F3.Text & vbCrLf
Clipboard.SetText T1F4.Text & vbCrLf
End Sub
Private Sub CommandButton2_Click()
(Will Reset all textfields and load Form 1 Havn't figured this out yet)
End Sub
Private Sub CommandButton3_Click()
f4.Show
Me.Hide
End Sub
Re: String manipulation and forms
I have read your post, and tried to figure out what you want to accomplish, but I cannot figure it out. Do you mind explaining a little more?
Re: String manipulation and forms
aint read the whole but....... as i am assumin that u have prob just with clip board
Code:
Private Sub CommandButton1_Click()
Clipboard.Clear (This isn't working)
Clipboard.SetText T1F1.Text & vbCrLf
Clipboard.SetText T2F1.Text & vbCrLf
Clipboard.SetText T3F1.Text & vbCrLf
Clipboard.SetText T4F1.Text & vbCrLf
Clipboard.SetText T5F1.Text & vbCrLf
Clipboard.SetText T1F2.Text & vbCrLf
Clipboard.SetText T2F2.Text & vbCrLf
Clipboard.SetText T3F2.Text & vbCrLf
Clipboard.SetText T1F3.Text & vbCrLf
Clipboard.SetText T2F3.Text & vbCrLf
Clipboard.SetText T3F3.Text & vbCrLf
Clipboard.SetText T4F3.Text & vbCrLf
Clipboard.SetText T5F3.Text & vbCrLf
Clipboard.SetText T1F4.Text & vbCrLf
End Sub
^^^^^^^^^^^^^^^^^ replace dis with ^^^^^^^^^^^^^^^^^^^
Code:
Private Sub CommandButton1_Click()
Clipboard.Clear 'this will work
'and plz mention formname before control's
Clipboard.SetText = T1F1.Text & vbCrLf
Clipboard.SetText = Clipboard.SetText & Form1.T2F1.Text & vbCrLf
Clipboard.SetText = Clipboard.SetText & Form1.T3F1.Text & vbCrLf
Clipboard.SetText = Clipboard.SetText & Form1.T4F1.Text & vbCrLf
Clipboard.SetText = Clipboard.SetText & Form1.T5F1.Text & vbCrLf
Clipboard.SetText = Clipboard.SetText & Form2.T1F2.Text & vbCrLf
Clipboard.SetText = Clipboard.SetText & Form2.T2F2.Text & vbCrLf
Clipboard.SetText = Clipboard.SetText & Form2.T3F2.Text & vbCrLf
Clipboard.SetText = Clipboard.SetText & Form3.T1F3.Text & vbCrLf
Clipboard.SetText = Clipboard.SetText & Form3.T2F3.Text & vbCrLf
Clipboard.SetText = Clipboard.SetText & Form3.T3F3.Text & vbCrLf
Clipboard.SetText = Clipboard.SetText & Form3.T4F3.Text & vbCrLf
Clipboard.SetText = Clipboard.SetText & Form3.T5F3.Text & vbCrLf
Clipboard.SetText = Clipboard.SetText & Form4.T1F4.Text & vbCrLf
End Sub
Re: String manipulation and forms
RaJ is on the right track... but you can't assign to SetText, it's a method. Also, the part he added should be GetText, not SetText.
Re: String manipulation and forms
I think this is VBA, not VB6.
In VBA, probably you cannot access Clipboard directly but you have to use a DataObject from "Microsoft Forms 2.0 Object Library" as a bridge to Set and Get text data.
Code:
Private Sub CommandButton1_Click()
Dim myData As New DataObject
Dim sText As String
sText = UserForm1.T1F1 & vbCrLf & _
UserForm1.T2F1 & vbCrLf & _
UserForm1.T3F1 & vbCrLf & _
UserForm1.T4F1 & vbCrLf & _
UserForm1.T5F1 & vbCrLf & _
UserForm2.T1F2 & vbCrLf & _
UserForm2.T2F2 & vbCrLf & _
UserForm2.T3F2 & vbCrLf & _
UserForm3.T1F3 & vbCrLf & _
UserForm3.T2F3 & vbCrLf & _
UserForm3.T3F3 & vbCrLf & _
UserForm3.T4F3 & vbCrLf & _
UserForm3.T5F3 & vbCrLf & _
UserForm4.T1F4 & vbCrLf
myData.SetText sText
myData.PutInClipboard
Set myData = Nothing
End Sub
Private Sub CommandButton4_Click()
Dim myData As New DataObject
myData.GetFromClipboard
MsgBox myData.GetText
Set myData = Nothing
End Sub
Re: String manipulation and forms
i am 99% sure this is VB not VBA
Re: String manipulation and forms
In fact it can be any, VB or VBA. But with the code in Post#1, that uses "UserForm#" and "CommandButton#", so I guess this is VBA.
Clipboard object is available in VB but not in VBA. So in Form5, he got:
Code:
Clipboard.Clear (This isn't working)
Re: String manipulation and forms
I agree.....this is VBA
Moved to Office Development
Re: String manipulation and forms
Maybe I wasn't Clear enough, I'm Creating the project using MS Word 2003's VB editor. and it isn't just the clipboard feature that I'm having trouble with although your replies were a huge help in getting this project up and working. if you look at the original code I posted, you'll notice in my button code
Private Sub CommandButton1_Click()
f5.Show
Me.Hide
End Sub
Private Sub CommandButton2_Click()
f3.Show
Me.Hide
End Sub
What I'm doing is using this button to go back and forth between forms, however I'm Declaring them in the fallowing manner:
Dim f5 As New UserForm5
Dim f3 As New UserForm3
and I don't want a new form I want the same form I had already entered data into or to be able to repopulate the form with the data that had already been entered into the textfields.
Thank You for all Your Help!!!
Re: String manipulation and forms
Well, then do this:
f3.Show
instead of this
Dim f3 As New UserForm3
It f3 is simply hidden, then it isn't unloaded....if it isn't unloaded then the textbox entries should still be in place.
Re: String manipulation and forms
Why do you need to declare 5 new form objects f1, f2, ... f5 with Dim f# As New UserForm# ???
Just simply use UserForm# instead of f#
Re: String manipulation and forms
I Just wanted to thank all of you for your assistance! I was able to get my project up and working and everything works great!