Save button using toolbar

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • squrel
    New Member
    • Jan 2008
    • 143

    Save button using toolbar

    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]
    Last edited by Dököll; Jun 17 '08, 01:30 AM. Reason: [code=vb] code tags...
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Greetings, squrel!

    I am not sure what the problem is, are you having problems with just your save mechanism? Did you know you can run the code in debug mode to follow what is happening. Please write if you need to know how to do that.

    Do stay tuned for a better answer on this one, like I said I am not certain how this could go.

    In a bit!

    Dököll

    Comment

    • squrel
      New Member
      • Jan 2008
      • 143

      #3
      plz tel me how to run it in a dubug mode... and non of my button is working... dont knw why? thank u

      Comment

      • QVeen72
        Recognized Expert Top Contributor
        • Oct 2006
        • 1445

        #4
        Hi,

        First Remove the error Handling and Run the Code.
        Keep a BreakPoint on First Line of the Code.
        and Check the Run-Sequence..

        Regards
        Veena

        Comment

        • squrel
          New Member
          • Jan 2008
          • 143

          #5
          Hi... i have changed the code to this but still i have error in this line :

          'txtAddressId.T ext = GetNextCode("Ad dress", "AdrID")


          why my getnextcode is not working? it gives me the error of Sub or function not defined? i dont get wht is the problem.... plz help... thankx



          Option Explicit

          Private Sub Form_Initialize ()
          On Error GoTo ChkErr
          Db.Close
          Db.ConnectionSt ring = pStrConnectionS tring
          Db.ConnectionTi meout = 0
          Db.Open
          Db.CursorLocati on = adUseClient
          DoEvents
          Exit Sub
          ChkErr:
          If Err.Number > 0 Then
          MsgBox Err.Number & vbNewLine & Err.Description
          Call ErrHand(Me.Capt ion, "Form_Initializ e")
          'Resume Next
          End If
          End Sub
          Private Sub Form_Load()
          On Error GoTo ChkErr
          FormUpdateSQL1. ConnectionStrin g = pStrConnectionS tring
          FormUpdateSQL1. TableName = "Address"
          FormUpdateSQL1. FieldList = "AdrId;AdrOf;Ad dress;City;Pin; Entrydt;Closedt ;Ind;"
          FormUpdateSQL1. ControlList = "txtId;cmbadrof ;txtAddress;txt City;txtPin;DTP entrydt;DTPclos edt;ChkInd;"
          FormUpdateSQL1. ViewFields = "AdrId;AdrOf;Ad dress;City;Pin; Entrydt;Closedt ;Ind;"
          FormUpdateSQL1. FormatString = "AdrId;AdrOf;Ad dress;City;Pin; Entrydt;Closedt ;Ind;"
          FormUpdateSQL1. DoVisible 4, False
          FormUpdateSQL1. DoVisible 6, False
          FormUpdateSQL1. DoVisible 8, False
          FormUpdateSQL1. AllowEdit = True
          FormUpdateSQL1. Refresh
          cmbadrof.Enable d = False
          Call Grid_Data
          Exit Sub
          ChkErr:
          If Err.Number > 0 Then
          MsgBox Err.Number & vbNewLine & Err.Description
          Call ErrHand("Addres s", "Form_Load" )
          'Resume Next
          End If

          Grid_Data
          End Sub
          Public Sub Grid_Data()
          On Error GoTo ChkErr
          Adodc1.Connecti onString = pStrConnectionS tring
          Adodc1.RecordSo urce = "Select AdrID as ID,Adrof,Addres s,City,Pin,entr ydt as EntryDate,close dt as CloseDate from Address"
          Adodc1.Refresh
          MSHFlexGrid1.Co lWidth(1) = 800
          MSHFlexGrid1.Co lWidth(2) = 1000
          MSHFlexGrid1.Co lWidth(3) = 2000
          MSHFlexGrid1.Co lWidth(4) = 1000
          MSHFlexGrid1.Co lWidth(5) = 800
          MSHFlexGrid1.Co lWidth(6) = 1000
          MSHFlexGrid1.Co lWidth(7) = 2000
          MSHFlexGrid1.Re fresh
          Exit Sub
          ChkErr:
          If Err.Number > 0 Then
          MsgBox Err.Number & vbNewLine & Err.Description
          Call ErrHand("Addres s", "Grid_Data" )
          'Resume Next
          End If
          End Sub

          Private Sub FormUpdateSQL1_ AddClick()
          cmbadrof.Enable d = True
          'txtAddressId.T ext = GetNextCode("Ad dress", "AdrID")
          cmbadrof.Enable d = True
          ChkInd.Value = 1
          End Sub

          Private Sub FormUpdateSQL1_ AfterControlsEn abled()
          cmbadrof.Enable d = True
          End Sub
          Private Sub FormUpdateSQL1_ AfterUpdate()
          cmbadrof.Enable d = False
          Call Grid_Data
          End Sub
          Private Sub FormUpdateSQL1_ BeforeValidate( )
          If cmbadrof.Text = "" Then
          MsgBox " Enter the selected address"
          cmbadrof.SetFoc us
          Exit Sub
          FormUpdateSQL1. CancelEvent = True
          End If
          End Sub
          Private Sub MSHFlexGrid1_Db lClick()
          FormUpdateSQL1. ViewRecord True, Val(MSHFlexGrid 1.Text)
          End Sub

          Comment

          • squrel
            New Member
            • Jan 2008
            • 143

            #6
            Is anyone can help me in this matter??

            Comment

            • QVeen72
              Recognized Expert Top Contributor
              • Oct 2006
              • 1445

              #7
              Originally posted by squrel

              txtAddressId.Te xt = GetNextCode("Ad dress", "AdrID")
              This looks like you are calling a Function...
              and you may not have that Function in your code, and the Error is the same...

              Regards
              Veena

              Comment

              • squrel
                New Member
                • Jan 2008
                • 143

                #8
                Hi
                In this code how can i get the next Id?? I mean if i have 7 record saved in this, when i press the add button i want the no 8 appears in my txtId... Can anyone help me plz... thankx a lot

                Comment

                • squrel
                  New Member
                  • Jan 2008
                  • 143

                  #9
                  Hi Guys..
                  I need some help here if anyone can.. thankx

                  Comment

                  • QVeen72
                    Recognized Expert Top Contributor
                    • Oct 2006
                    • 1445

                    #10
                    Hi,

                    Write this Function :
                    {AIRCODE}

                    [code=vb]
                    Private Function MyNextID() As Long
                    Dim RSI As New ADODB.RecordSet
                    MyNextID = 0
                    RSI.Open "Select Max(ID) From MyTable",Conn
                    If Not RSI.EOF Then
                    RSI.MoveFirst
                    MyNextID = Val(RSI(0) & "")
                    End If
                    MyNextID = MyNextID + 1
                    RSI.Close
                    Set RSI = Nothing
                    End Function
                    [/code]

                    Call the above Function, In cmdADD_Click
                    [code=vb]
                    txtID.Text = MyNextID
                    [/code]

                    Regards
                    Veena

                    Comment

                    • squrel
                      New Member
                      • Jan 2008
                      • 143

                      #11
                      Hi Veena..

                      That Code is not working in my project... my add function is this

                      Private Sub FormUpdateSQL1_ AddClick()

                      cmbadrfor.Enabl ed = True
                      'txtId.Text = GetNextCode("Ad dress", "AdrID")
                      cmbadrfor.Enabl ed = True
                      txtId.Enabled = False
                      ChkInd.Value = 1
                      End Sub

                      tht part of the code is not working in my function... wht else i can do..
                      thanks a lot

                      Comment

                      • QVeen72
                        Recognized Expert Top Contributor
                        • Oct 2006
                        • 1445

                        #12
                        Hi,

                        you are using VB6 or VBA....?

                        My code is for VB6

                        Regards
                        Veena

                        Comment

                        • squrel
                          New Member
                          • Jan 2008
                          • 143

                          #13
                          I m using VB6 with SQLserver 2000

                          Comment

                          • QVeen72
                            Recognized Expert Top Contributor
                            • Oct 2006
                            • 1445

                            #14
                            Hi,

                            Did you add the Function what I said in My previous post..?

                            Comment

                            • squrel
                              New Member
                              • Jan 2008
                              • 143

                              #15
                              Yes i added tht function the same way u told me but it is not working and still getting error

                              Comment

                              Working...