If-else,skipping else

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vbbeginner07
    New Member
    • Dec 2007
    • 103

    If-else,skipping else

    Follow the code:

    code:vb

    If mesge = vbOK Then
    rs.Open "select * from empdetail where name = '" & mName & "'", conn, adOpenStatic, adLockOptimisti c
    txtid.Text = rs!id
    txtid.Enabled = False
    Else
    txtid.Text = ""
    txtid.Enabled = True

    End If
    rs.Close
    Set rs = Nothing

    starts from if the control not moving to else?
    What's wrong with the code? Anybody please explain.
    Last edited by Killer42; Dec 29 '07, 12:37 PM.
  • creative1
    Contributor
    • Sep 2007
    • 274

    #2
    Whats going on before this statement:
    If mesge = vbOK Then

    Comment

    • Vbbeginner07
      New Member
      • Dec 2007
      • 103

      #3
      Originally posted by creative1
      Whats going on before this statement:
      If mesge = vbOK Then
      It's a code to remove a particular selected item from a listvieew, where mesge is declared as Integer.

      [CODE=vb]mesge = 1
      hello = Trim(ListView1. SelectedItem)
      MsgBox "Are you Sure you Want to Delete " & hello & "?", vbOKCancel, "ERROR"[/CODE]
      Last edited by Killer42; Dec 29 '07, 12:39 PM. Reason: Added [CODE=vb] tag

      Comment

      • creative1
        Contributor
        • Sep 2007
        • 274

        #4
        I think you should use vbYesNo insteaed of vbOKCancel.

        Comment

        • VijaySofist
          New Member
          • Jun 2007
          • 107

          #5
          Originally posted by Vbbeginner07
          its a code to remove a particularly selected ietem froam alistvieew,wher e mesge declared aas integer


          [CODE=vb]mesge = 1
          hello = Trim(ListView1. SelectedItem)
          MsgBox "Are you Sure you Want to Delete " & hello & "?", vbOKCancel, "ERROR"[/CODE]
          Hi!

          Declare mesge As String and you did't pass the MsgBox Result to the variable mesge . Use the following Code
          [CODE=vb]Dim mesge as String
          mesge = MsgBox ("Are you Sure you Want to Delete " & hello & "?", vbOKCancel, "ERROR")[/CODE]

          All The Best

          With Regards
          Vijay. R
          Last edited by Killer42; Dec 29 '07, 12:39 PM.

          Comment

          • creative1
            Contributor
            • Sep 2007
            • 274

            #6
            Originally posted by Vbbeginner07
            its a code to remove a particularly selected ietem froam alistvieew,wher e mesge declared aas integer


            mesge = 1
            hello = Trim(ListView1. SelectedItem)
            MsgBox "Are you Sure you Want to Delete " & hello & "?", vbOKCancel, "ERROR"
            do not declare msg as string it will solve your problem.

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              Originally posted by Vbbeginner07
              ... starts from if the control not moving to else????
              What's wrong with the code? Anybody please explain
              I know you already have a number of responses to this question, but I'd like to get a better description of what the actual problem is. We know for a fact that VB will always execute either the IF block or the ELSE block. So what, precisely, is the problem?

              And, have you tried stepping through the code, examining values to determine exactly what's happening? These built-in debugging tools should always be your first port of call.

              By the way, what version of VB is this? (I'm guessing VB6.)

              Comment

              • Vbbeginner07
                New Member
                • Dec 2007
                • 103

                #8
                Originally posted by Killer42
                I know you already have a number of responses to this question, but I'd like to get a better description of what the actual problem is. We know for a fact that VB will always execute either the IF block or the ELSE block. So what, precisely, is the problem?
                And, have you tried stepping through the code, examining values to determine exactly what's happening? These built-in debugging tools should always be your first port of call.
                By the way, what version of VB is this? (I'm guessing VB6.)
                yes,its vb 6,i have to update a particular dat in a lsit view control,so ihave clicked one,then after disabled the id,which is the pk,i have tocheck thru each boxes and then update the new values to recordset....
                any new methods favouring this???

                Comment

                • debasisdas
                  Recognized Expert Expert
                  • Dec 2006
                  • 8119

                  #9
                  Originally posted by Vbbeginner07
                  yes,its vb 6,i have to update a particular dat in a lsit view control,so ihave clicked one,then after disabled the id,which is the pk,i have tocheck thru each boxes and then update the new values to recordset....
                  any new methods favouring this???
                  Is this a different question ?

                  Kindly write in clear concise language using correct grammar and spelling

                  Comment

                  • Vbbeginner07
                    New Member
                    • Dec 2007
                    • 103

                    #10
                    Originally posted by debasisdas
                    Is this a different question ?

                    Kindly write in clear concise language using correct grammar and spelling
                    Really sorry for that!
                    I am updating a particular item in a list view control where id is the primary key, hence after clicking any item, the records related to the id will be displayed in texboxes, so could you please suggest a convenient method for this?
                    Right after clicking an item, the records related to those are displayed in the textboxes, but I cannot update that.
                    Here's my code
                    [CODE=vb]If mesge = vbOK Then
                    rs.Open "select * from empdetail where name = '" & mName & "'", conn, adOpenStatic, adLockOptimisti c
                    Form1.txtid.Tex t = rs!id
                    Form1.txtname.T ext = rs!Name
                    Form1.txtwhr.Te xt = rs!whours
                    Form1.txtrate.T ext = rs!Rate
                    Form1.txtorate. Text = rs!otrate
                    txtid.Enabled = False
                    txtname.SetFocu s
                    Form1.txtname.S etFocus
                    else
                    conn.Execute "update empdetail set Name= '" & txtname & "',whours=' " & txtwhrs & "',rate ='" & txtrate & "',otrate ='" & txtorate & "'"
                    MsgBox "UPDATED NEW DETAILS", vbOKOnly, "UPDATED RECORDS"
                    rs.Close
                    Set rs = Nothing
                    End If[/CODE]

                    Please go through.
                    Last edited by Killer42; Dec 31 '07, 07:58 AM. Reason: Added CODE=vb tag

                    Comment

                    • debasisdas
                      Recognized Expert Expert
                      • Dec 2006
                      • 8119

                      #11
                      what is the problem with current code ?

                      Are you unable to update ?
                      try to commit after update.

                      use
                      [code=vb]
                      conn.begintrans
                      conn.execute "sql update statment"
                      conn.committran s
                      [/code]

                      Comment

                      • Vbbeginner07
                        New Member
                        • Dec 2007
                        • 103

                        #12
                        Originally posted by debasisdas
                        what is the problem with current code ?

                        Are you unable to update ?
                        try to commit after update.

                        use
                        [code=vb]
                        conn.begintrans
                        conn.execute "sql update statment"
                        conn.committran s
                        [/code]
                        yes,im unble to update that,im using a a command button and atfirst im selecting from a list view,so related records are shown,when im click the command button for updating new values,the reeore occurs:
                        cannot convert varchar to nummeric??

                        Comment

                        • debasisdas
                          Recognized Expert Expert
                          • Dec 2006
                          • 8119

                          #13
                          Originally posted by Vbbeginner07
                          when im click the command button for updating new values,the reeore occurs:
                          cannot convert varchar to nummeric??
                          that simply means you are passing a value of wrong type . try convet to proper type before processing.

                          Comment

                          • Vbbeginner07
                            New Member
                            • Dec 2007
                            • 103

                            #14
                            Originally posted by debasisdas
                            that simply means you are passing a value of wrong type . try convet to proper type before processing.
                            no its because its taking the text box values as""!!!

                            Comment

                            • Killer42
                              Recognized Expert Expert
                              • Oct 2006
                              • 8429

                              #15
                              Ok, so if I'm understanding this, the problem is that your UPDATE command includes, for example, rate = ''.

                              If rate is a numeric field, then I see two potential problems with this:
                              1. The value should not be delimited with quotes (or anything else).
                              2. If the value is empty, then you should either leave the field out of the UPDATE, or pass 0 as the value.

                              Comment

                              Working...