|
-
Oct 25th, 2003, 05:08 AM
#1
Thread Starter
Fanatic Member
quick question for any one reading this
quick question for any one reading this
i have main mdi parant with a function on it , which needs to access the value of a textbox on a child form so i added the form to a module and when i code to acess the form i get all the parameters fine, but when i run the app i get an error message saying "object reference not set not set to an instance of the object"
i normally access forms in this way but ive never actully accessed a child from a parant but i cant see if being that difficult
I am curretly building a defect management system for software and web developers,
If you wana try it out (beta test) and keep it for free just send me a message
-
Oct 25th, 2003, 09:42 AM
#2
Lively Member
-
Oct 25th, 2003, 11:37 AM
#3
Thread Starter
Fanatic Member
mdiparant code
==================
'function to control mdi forms
Public Sub ShowSingleInstance(ByVal childType As Type)
For Each child As Form In Me.MdiChildren
If child.GetType Is childType Then
child.Activate() 'already loaded so bring to foreground
Return
End If
Next
Dim frm As Form = Activator.CreateInstance(childType) 'not loaded yet so create
frm.MdiParent = Me
frm.Show()
End Sub
========= function that controls mdi childs
========= function that controls thr clicks on the toolbar
Private Sub toolbar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick
Select Case ToolBar1.Buttons.IndexOf(e.Button)
Case 0
frmCustomer_Add.DoDataSave("Customer_Add")
Case 1
Case 2
Case 4
Case 6
Case 7
Case 8
Case 10
Case 12
Case 13
Case 14
End Select
End Sub
================================
case 0 the first button frmCustomer_ADD. is defined in my module
Public frmCustomer_Add As New Customer_Add
if i define the form as NEW then i dont get the error however i cant seem to pick up any text from the text boxes on the form
on my child form i have a button calling the same function and it works fine, so it looks like the toolbar button is getting confused
I am curretly building a defect management system for software and web developers,
If you wana try it out (beta test) and keep it for free just send me a message
-
Oct 25th, 2003, 01:06 PM
#4
Lively Member
Where's the code for DoDataSave.
-
Oct 25th, 2003, 01:57 PM
#5
Thread Starter
Fanatic Member
Public Function DoDataSave(ByVal ChildName As String)
Try
MsgBox(ChildName)
Dim Cmd As OleDbCommand = New OleDbCommand
Cmd.CommandType = CommandType.StoredProcedure
Cmd.Connection = MyConnection
Select Case LCase(ChildName)
Case LCase("Customer_Add")
MsgBox(frmCustomer_Add.txtFullName.Text & " here")
With Cmd
.CommandText = "InsNewCustomer"
.Parameters.Add("@FullName", frmCustomer_Add.txtFullName.Text)
.Parameters.Add("@Building", frmCustomer_Add.txtBuilding.Text)
.Parameters.Add("@Street", frmCustomer_Add.txtStreet.Text)
.Parameters.Add("@Street2", frmCustomer_Add.txtStreet2.Text)
.Parameters.Add("@Town", frmCustomer_Add.txtTown.Text)
.Parameters.Add("@County", frmCustomer_Add.txtCounty.Text)
.Parameters.Add("@Postcode", frmCustomer_Add.txtPostCode.Text)
.Parameters.Add("@Country", 1)
.Parameters.Add("@Company", frmCustomer_Add.txtCompany.Text)
.Parameters.Add("@vat", frmCustomer_Add.txtVatNumber.Text)
.Parameters.Add("@Tel", "")
.Parameters.Add("@Fax", "")
.Parameters.Add("@FirstEmail", "")
.Parameters.Add("@SecondEmail", "")
.Parameters.Add("@Mobile", "")
.Parameters.Add("@BillingAddress", 1)
End With
Case Else
MsgBox("No data matching this command")
End Select
MyConnection.Open()
Cmd.ExecuteNonQuery()
MyConnection.Close()
MsgBox("saved")
Catch er As Exception
MsgBox(er.ToString)
Finally
MyConnection.Close()
End Try
End Function
I am curretly building a defect management system for software and web developers,
If you wana try it out (beta test) and keep it for free just send me a message
-
Oct 25th, 2003, 02:10 PM
#6
You can break out the ShowSingleInstance method into two. One that returns the single instance and one that shows it.
VB Code:
'function to return mdi child
Public Function GetSingleInstance(ByVal childType As Type) As Form
For Each child As Form In Me.MdiChildren
If child.GetType Is childType Then
Return child 'already loaded so return
End If
Next
Dim frm As Form = Activator.CreateInstance(childType) 'not loaded yet so create
Return frm
End Function
'function to show mdi forms
Public Sub ShowSingleInstance(ByVal childType As Type)
Dim child As Form = GetSingleInstance(childType)
'make sure everything is set
If child.MdiParent Is Nothing Then child.MdiParent = Me
'didn't test the part below but it should work
If Not child.Visible Then
child.Show()
Else
child.Activate()
End If
End Sub
'syntax for use
Dim frm As Form1 = GetSingleInstance(GetType(Form1))
'if you have option strict on use this
'Dim frm As Form1 = CType(GetSingleInstance(GetType(Form1)), Form1)
MsgBox(frm.TextBox1.Text)
-
Oct 25th, 2003, 02:15 PM
#7
VB Code:
Public Function DoDataSave(ByVal ChildName As String)
Try
MsgBox(ChildName)
Dim Cmd As OleDbCommand = New OleDbCommand
Cmd.CommandType = CommandType.StoredProcedure
Cmd.Connection = MyConnection
Select Case LCase(ChildName)
Case LCase("Customer_Add")
Dim frm As frmCustomer_Add=GetSingleInstance(gettype(frmCustomer_Add))
MsgBox(frm.txtFullName.Text & " here")
With Cmd
.CommandText = "InsNewCustomer"
.Parameters.Add("@FullName", frm.txtFullName.Text)
.Parameters.Add("@Building", frm.txtBuilding.Text)
.Parameters.Add("@Street", frm.txtStreet.Text)
.Parameters.Add("@Street2", frm.txtStreet2.Text)
.Parameters.Add("@Town", frm.txtTown.Text)
.Parameters.Add("@County", frm.txtCounty.Text)
.Parameters.Add("@Postcode", frm.txtPostCode.Text)
.Parameters.Add("@Country", 1)
.Parameters.Add("@Company", frm.txtCompany.Text)
.Parameters.Add("@vat", frm.txtVatNumber.Text)
.Parameters.Add("@Tel", "")
.Parameters.Add("@Fax", "")
.Parameters.Add("@FirstEmail", "")
.Parameters.Add("@SecondEmail", "")
.Parameters.Add("@Mobile", "")
.Parameters.Add("@BillingAddress", 1)
End With
Case Else
MsgBox("No data matching this command")
End Select
MyConnection.Open()
Cmd.ExecuteNonQuery()
MyConnection.Close()
MsgBox("saved")
Catch er As Exception
MsgBox(er.ToString)
Finally
MyConnection.Close()
End Try
End Function
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
|