Solved

VB6: Copy, Cut & Paste from/to TextBox in MDI form?

Posted on 2004-10-20
15
811 Views
Last Modified: 2008-01-09
Hi,

When I try to Copy, Cut or Paste from or to TextBox in my MDI child form I am getting an Error. Does it make any diferent to Copy/Paste from/to an MDI form?

Thank you.
0
Comment
Question by:2Angel
15 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 12356049
Can you post a piece of your code and the error you're getting !
0
 
LVL 2

Author Comment

by:2Angel
ID: 12356111
Hi,
I tried both methods:
The simple one
                 Clipboard.SetText
Or this one
                 http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/viewQuestionPrinterFriendly.jsp?qid=20561050

The error on both methods is: "Argument not optional"

Thanks
0
 
LVL 10

Expert Comment

by:anv
ID: 12356252
hi

did u try this..

Private Sub Command1_Click()
'copy

Clipboard.SetText ("SomeTextToCopyFrom HERE")

End Sub

Private Sub Command2_Click()
'Paste
   Text1.Text = Clipboard.GetText()
End Sub
0
 
LVL 2

Author Comment

by:2Angel
ID: 12356504
Hi,

Thank you for your comment, any, but I did. This is working but its not giving me the solustion.
I want to Copy/Paste to the control that the user is "standing on" (the TextBox that is in focus).

Thanks.
0
 
LVL 10

Accepted Solution

by:
anv earned 85 total points
ID: 12356533
alright then...

use this then

MDIForm1.ActiveControl.Text = Clipboard.GetText
0
 
LVL 2

Author Comment

by:2Angel
ID: 12356657
Hi,

Thanks again...

This time I don't recive the error but it's doesn't do anything...
ByTheWay, The Paste (MDIForm1.ActiveControl.Text = Clipboard.SetText) is giving me the error above....

Please, my you have another one....

P.S. - Your Registration Date is on my Birthdate....

Thanks!
0
 
LVL 10

Expert Comment

by:anv
ID: 12356688
where did u write the code for above statement?? i mean in shich event are u calling it...

actually ActiveControl is the control of the form that currently has the focus...

so if u are giving the code in the click event of a command button...then u need to set the focus to the control or text box...first..then u need to execute the above statement..
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 10

Expert Comment

by:anv
ID: 12356690
>>P.S. - Your Registration Date is on my Birthdate....

Good to know that..

:))
0
 
LVL 2

Author Comment

by:2Angel
ID: 12356718
Hi,

The statement is under the menu Copy...
The control is on focus becaose I click on a control, mark the data and then click on the menu->copy (or Ctrl+C).

p.s. - "Neeru Verma" What is the source of this name? Does it has a meaning?

Regards.
0
 
LVL 10

Expert Comment

by:anv
ID: 12356770
hi 2Angel
it should work

as its working here very smoothly...

can u paste the code here

>>p.s. - "Neeru Verma" What is the source of this name? Does it has a meaning?

"Verma" is my husband's Last Name
in hindi "Neer" means "Water".. "Neeru" means "Holy Water"
0
 
LVL 16

Assisted Solution

by:jimbobmcgee
jimbobmcgee earned 20 total points
ID: 12357661
If ActiveControl is the control that has focus, perhaps clicking the menu item is shifting the focus to the menu.  Maybe the Click event of the menu is run _before_ the focus is passed back to the text box.

If that is the case, perhaps:

       Public ctlLastControl as Control

       Private Sub Text1_LostFocus()

            Set ctlLastControl = Text1

       End Sub

       Private Sub mnuCopy_Click()

           Clipboard.Clear
           Clipboard.SetText ctlLastControl.Text

       End Sub

       Private Sub mnuPaste_Click()

           Clipboard.Clear
           ctlLastControl.Text = ctlLastControl.Text & Clipboard.GetText

       End Sub


Incidently, are you clearing the clipboard before you set your text?  

Or are you perhaps saying:

       Clipboard.SetText Text1.Text
       ...
       Text1.Text = Clipboard.GetText

because, if you are, then Text1.Text will appear not to change...

Just some ideas; HTH...

J.
0
 
LVL 2

Author Comment

by:2Angel
ID: 12357764
Wow - very interesting about you name.

>>"Verma" is my husband's Last Name
again wow - you are only 24....


Well, my code is very simple. I have an MDI Main form (frmMain) and MDIChild (frmTable).
frmTable has a few TextBoxs named txtBx(0).... and so on... (this form is connected to an access data base).
The main form has a menu I've created by the MenuEditor.

So, I have this code on the main form:

Private Sub mnuEditCopy_click()
     frmTable.ActiveControl.Text = Clipboard.GetText
End Sub

Private Sub mnuEditPaste_click()
     Clipboard.SetText frmTable.ActiveControl.Text
End Sub


Thank you for helping and have a nice day...

0
 
LVL 32

Assisted Solution

by:Erick37
Erick37 earned 20 total points
ID: 12357894
Do you have this reversed?
Copy should copy to clipboard
Paste should paste to control

Private Sub mnuEditCopy_click()
    Clipboard.SetText frmTable.ActiveControl.Text
End Sub

Private Sub mnuEditPaste_click()
    frmTable.ActiveControl.Text = Clipboard.GetText
End Sub
0
 
LVL 2

Author Comment

by:2Angel
ID: 12358331

O.K. - I am sorry, I got it......

The problem was that this is an MDI application and I need to look for the active form first...   so, I this is the answere:

Private Sub mnuEditCopy_click()
    Clipboard.SetText ActiveForm.ActiveControl.Text
End Sub

Private Sub mnuEditPaste_click()
    ActiveForm.ActiveControl.Text = Clipboard.GetText
End Sub

Well, thanks every one!!! Anyhow I will split the points

p.s. - Neeru Verma, take care......
0
 
LVL 10

Expert Comment

by:anv
ID: 12366391
thanx 2Angel

:)
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now