|
-
May 19th, 2005, 09:54 AM
#1
Thread Starter
Member
Command Buttons - RESOLVED
I have 2 command buttons on one form lets call this form1. On form2 I have a drive, directory, and file listbox. Lets say I click on command button1, it opens form2 and allows me to select the drive, directory, and file. I want it to write back to form1 in a text box. If I click command button2 I want it to do the same thing but write back to form1 to a different text box. What I am asking is how to determine which button is clicked on form1 and carry that over to form2?
Thanks.
Last edited by odamsr; Jun 1st, 2005 at 05:16 PM.
-
May 19th, 2005, 10:03 AM
#2
Re: Command Buttons
 Originally Posted by odamsr
I have 2 command buttons on one form lets call this form1. On form2 I have a drive, directory, and file listbox. Lets say I click on command button1, it opens form2 and allows me to select the drive, directory, and file. I want it to write back to form1 in a text box.
VB Code:
'from the Filelist box on Form2
Private Sub File1_Click()
Form1.Text1.Text = File1.Filename
End Sub
 Originally Posted by odamsr
If I click command button2 I want it to do the same thing but write back to form1 to a different text box.
VB Code:
'from Form1
Private Sub Command2_Click()
Text2.Text = Form2.File1.Filename
End Sub
Note: Make sure a file is selected before clicking on Command2.
Is this what you wanted?
-
May 19th, 2005, 10:03 AM
#3
Re: Command Buttons
Instead of keeping track of which button was clicked maybe you should keep track of which text box that you want to be updated.
I assume that Form2 has an OK button and that you want to show it modally. Now let's say that Command1 on Form1 will update Text1 and Command2 will update Text2. Then add the following code to Form2:
VB Code:
Private mtxtBox As TextBox
Public Sub ShowMe(txtBox As TextBox)
Set mtxtBox = txtBox
Me.Show vbModal
End Sub
Private Sub cmdOK_Click()
'update the text box.
mtxtBox.Text = Drive1.Drive & Dir1.Dir & "\" & File1.File 'or whatever
Unload Me
End Sub
In the CommandX_Click of Form1 use code simular to this:
VB Code:
Private Sub Command1_Click()
Call Form2.ShowMe(Text1)
End Sub
Private Sub Command2_Click()
Call Form2.ShowMe(Text2)
End Sub
-
May 19th, 2005, 10:07 AM
#4
Re: Command Buttons
You may set some flag (boolean, string, integer, ...) on Form1 and check it while on Form2:
VB Code:
'Form1
Option Explicit
Public strButton As String
Private Sub Command1_Click()
'...
strButton = "Button1"
'...
End Sub
'Form2
'somewhere in the code:
If Form1.strButton = "Button1" Then ...
-
May 19th, 2005, 11:27 AM
#5
Thread Starter
Member
Re: Command Buttons
Thanks everyone. I used your code, Joacim and it worked like a charm. Thanks to everyone.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|