Hello everyone,
I m using some button using toolbar such as Add,Save,View,. ... my save button is not working.... it doesnt give me any error but does not save to my database.... or showing in my gird... Plz Help
here is my code for save button
[CODE=VB]
Private Sub Toolbar1_Button Click(ByVal Button As MSComctlLib.But ton)
On Error GoTo ChkErr
If Button.Index = 1 Then
Mode = "Add"
Call AddMode
Call ClearControl
Toolbar1.Button s.Item(1).Enabl ed = False ' Add
Toolbar1.Button s.Item(2).Enabl ed = False ' View
Toolbar1.Button s.Item(3).Enabl ed = False ' Sort
Toolbar1.Button s.Item(4).Enabl ed = False ' Edit
Toolbar1.Button s.Item(5).Enabl ed = True ' save
Toolbar1.Button s.Item(9).Enabl ed = True 'Exit
End If
If Button.Index = 4 Then
'If Val(MSHFlexGrid 1.TextMatrix(MS HFlexGrid1.RowS el, 8)) = "0" Then
Mode = "Edit"
Toolbar1.Button s.Item(5).Enabl ed = True ' save buton
Call Enable
Else
MsgBox " Cannot Edit "
End If
If Button.Index = 5 Then
Call SaveMode
Call ClearControl
Call Desable
MsgBox " Record Saved For Id '" & txtId.Text & "'"
Toolbar1.Button s.Item(5).Enabl ed = False
Toolbar1.Button s.Item(1).Enabl ed = True ' Add
Call Address
End If
'End If
If Button.Index = 2 Then ' View
'Toolbar1.Butto ns.Item(7).Enab led = False ' Final
Toolbar1.Button s.Item(1).Enabl ed = False ' Add
Toolbar1.Button s.Item(4).Enabl ed = True ' Edit
End If
If Button.Index = 7 Then ' Cancel
Db.Execute "Update Address"
Call Address
End If
If Button.Index = 9 Then ' Exit
Unload Me
End If
Exit Sub
ChkErr:
If Err.Number > 0 Then
MsgBox Err.Number & vbNewLine & Err.Description
Call ErrHand(Me.Capt ion, "cmdSave_Click" )
End If
End Sub
Public Function SaveMode()
'On Public Function SaveMode()
If Mode = "Add" Then
' To Get ReqNo from Mslastdoc
Dim Rs As New ADODB.Recordset
If Rs.State = adStateOpen Then Rs.Close
Rs.Open ("SELECT * FROM MsLastDoc where YY ='" & FinancialYear & "'"), Db, adOpenKeyset, adLockPessimist ic
txtId.Text = Rs("LastDocNo") .Value + 1
Rs.Close
' End
' Save LastDoc
Dim LastDoc As New ADODB.Recordset
Dim DocNo As Integer
DocNo = Val(txtId.Text)
If LastDoc.State = adStateOpen Then LastDoc.Close
LastDoc.Open ("Select * From MsLastDoc where YY ='" & FinancialYear & "' "), Db, adOpenKeyset, adLockPessimist ic
Db.Execute "Update MsLastDoc set LastDocNo ='" & DocNo & "' where YY ='" & FinancialYear & "' "
' End Save
End If
Call SaveAddress
Call ClearControl
End Function
Public Function SaveAddress()
Db.Execute " Delete from Adress where Id = '" & txtId.Text & "' "
Dim RsAddress As New ADODB.Recordset
'If RsReqHdr.State = adStateOpen Then RsReqHdr.Close
RsAddress.Open ("Address"), Db, adOpenKeyset, adLockPessimist ic
With RsAddress
RsAddress.AddNe w
.Fields("Id") = Val(txtId.Text)
.Fields("Addres sof") = Val(cmbadrof.Te xt)
.Fields("Addres s") = Val(txtAddress. Text)
.Fields("city") = Val(txtCity.Tex t)
.Fields("Pin") = Val(txtPin.Text )
.Fields("entryd t") = Format(DTPentry dt, "DD-MMM-YYYY")
.Fields("closed t") = Format(DTPClose dt, "DD-MMM-YYYY")
.Update
End With
RsAddress.Close
End Function
[/CODE]
I m using some button using toolbar such as Add,Save,View,. ... my save button is not working.... it doesnt give me any error but does not save to my database.... or showing in my gird... Plz Help
here is my code for save button
[CODE=VB]
Private Sub Toolbar1_Button Click(ByVal Button As MSComctlLib.But ton)
On Error GoTo ChkErr
If Button.Index = 1 Then
Mode = "Add"
Call AddMode
Call ClearControl
Toolbar1.Button s.Item(1).Enabl ed = False ' Add
Toolbar1.Button s.Item(2).Enabl ed = False ' View
Toolbar1.Button s.Item(3).Enabl ed = False ' Sort
Toolbar1.Button s.Item(4).Enabl ed = False ' Edit
Toolbar1.Button s.Item(5).Enabl ed = True ' save
Toolbar1.Button s.Item(9).Enabl ed = True 'Exit
End If
If Button.Index = 4 Then
'If Val(MSHFlexGrid 1.TextMatrix(MS HFlexGrid1.RowS el, 8)) = "0" Then
Mode = "Edit"
Toolbar1.Button s.Item(5).Enabl ed = True ' save buton
Call Enable
Else
MsgBox " Cannot Edit "
End If
If Button.Index = 5 Then
Call SaveMode
Call ClearControl
Call Desable
MsgBox " Record Saved For Id '" & txtId.Text & "'"
Toolbar1.Button s.Item(5).Enabl ed = False
Toolbar1.Button s.Item(1).Enabl ed = True ' Add
Call Address
End If
'End If
If Button.Index = 2 Then ' View
'Toolbar1.Butto ns.Item(7).Enab led = False ' Final
Toolbar1.Button s.Item(1).Enabl ed = False ' Add
Toolbar1.Button s.Item(4).Enabl ed = True ' Edit
End If
If Button.Index = 7 Then ' Cancel
Db.Execute "Update Address"
Call Address
End If
If Button.Index = 9 Then ' Exit
Unload Me
End If
Exit Sub
ChkErr:
If Err.Number > 0 Then
MsgBox Err.Number & vbNewLine & Err.Description
Call ErrHand(Me.Capt ion, "cmdSave_Click" )
End If
End Sub
Public Function SaveMode()
'On Public Function SaveMode()
If Mode = "Add" Then
' To Get ReqNo from Mslastdoc
Dim Rs As New ADODB.Recordset
If Rs.State = adStateOpen Then Rs.Close
Rs.Open ("SELECT * FROM MsLastDoc where YY ='" & FinancialYear & "'"), Db, adOpenKeyset, adLockPessimist ic
txtId.Text = Rs("LastDocNo") .Value + 1
Rs.Close
' End
' Save LastDoc
Dim LastDoc As New ADODB.Recordset
Dim DocNo As Integer
DocNo = Val(txtId.Text)
If LastDoc.State = adStateOpen Then LastDoc.Close
LastDoc.Open ("Select * From MsLastDoc where YY ='" & FinancialYear & "' "), Db, adOpenKeyset, adLockPessimist ic
Db.Execute "Update MsLastDoc set LastDocNo ='" & DocNo & "' where YY ='" & FinancialYear & "' "
' End Save
End If
Call SaveAddress
Call ClearControl
End Function
Public Function SaveAddress()
Db.Execute " Delete from Adress where Id = '" & txtId.Text & "' "
Dim RsAddress As New ADODB.Recordset
'If RsReqHdr.State = adStateOpen Then RsReqHdr.Close
RsAddress.Open ("Address"), Db, adOpenKeyset, adLockPessimist ic
With RsAddress
RsAddress.AddNe w
.Fields("Id") = Val(txtId.Text)
.Fields("Addres sof") = Val(cmbadrof.Te xt)
.Fields("Addres s") = Val(txtAddress. Text)
.Fields("city") = Val(txtCity.Tex t)
.Fields("Pin") = Val(txtPin.Text )
.Fields("entryd t") = Format(DTPentry dt, "DD-MMM-YYYY")
.Fields("closed t") = Format(DTPClose dt, "DD-MMM-YYYY")
.Update
End With
RsAddress.Close
End Function
[/CODE]
Comment