Microsoft
Software
Hardware
Network
Question : Visual Basic - populating a varying text box from another form
I have one form
CallingForm
with two textboxes and related command buttons beside each. So
txtCompany
and
cmdCompany
, and
txtState
and
cmdState
. Both command buttons, when clicked, show the same form
SelectForm
with a single DataGrid listing CompanyName, State, etc. The user then selects a record from the DataGrid in SelectForm. I want SelectForm to return information back to CallingForm, populating the correct text box, based on which command button (and therefore textbox) was clicked in CallingForm.
If cmdCompany was clicked in CallingForm, I want SelectForm's DataGrid selection to populate CallingForm's txtCompany text box.
If cmdState was clicked in CallingForm, I want SelectForm's DataGrid selection to populate CallingFroms' txtState text box.
I know how to reference the column I need in the data grid and knew how to populate the text box back in CallingForm when I was only dealing with one text box, but now I'm struggling with how to reference the text box in CallingForm, now that I am dealing with a variable of sorts as to which text box in CallingForm I want to populate.
Answer : Visual Basic - populating a varying text box from another form
Display SelectForm as a modal dialog with "vbModal" and then grab the info from it back in CallingForm:
Private Sub cmdCompany_Click()
Dim sf As New SelectForm
sf.Show vbModal ' <--- code in CallingForm STOPS here until "sf" is hidden
' ...grab some info directly from the HIDDEN "sf" instance...
Me.txtCompany.Text = sf.txtSomething.Text
End Sub
Private Sub cmdState_Click()
Dim sf As New SelectForm
sf.Show vbModal ' <--- code in CallingForm STOPS here until "sf" is hidden
' ...grab some info from "sf"...
Me.txtState.Text = sf.txtSomething.Text
End Sub
In SelectForm, you simpy HIDE the form in response to the "OK" button being clicked:
Private Sub cmdOK_Click()
Me.Hide ' <-- this causes the "modal" form to HIDE and execution to RETURN to CallingForm AFTER the .Show vbModal call line
End Sub
Random Solutions
BCM, Business Contact Manager, 2010 RTM cannot connect to remote sql database
Are multiple PHP session paths possible?
SSIS and variable issues
Could not reliably determine the server's fully qualified when trying to restart https service
Backup Exec 12 - can't install any updates - gives error 1324 "The path Program Files contains an invalid character"
How to program well
How to connect to network printer linux
can't get iPhone to connect to Exchange 2010 from outside...
Filtering the SSRS report based on multivalue multiple parameters passed to stored procedure
compile this code with Delphi 2010