By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,557 Members | 1,164 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,557 IT Pros & Developers. It's quick & easy.

If-else,skipping else

100+
P: 103
Follow the code:

code:vb

If mesge = vbOK Then
rs.Open "select * from empdetail where name = '" & mName & "'", conn, adOpenStatic, adLockOptimistic
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.
Dec 29 '07 #1
Share this Question
Share on Google+
14 Replies


100+
P: 274
Whats going on before this statement:
If mesge = vbOK Then
Dec 29 '07 #2

100+
P: 103
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.

Expand|Select|Wrap|Line Numbers
  1. mesge = 1
  2. hello = Trim(ListView1.SelectedItem)
  3. MsgBox "Are you Sure you Want to Delete " & hello & "?", vbOKCancel, "ERROR"
Dec 29 '07 #3

100+
P: 274
I think you should use vbYesNo insteaed of vbOKCancel.
Dec 29 '07 #4

VijaySofist
100+
P: 107
its a code to remove a particularly selected ietem froam alistvieew,where mesge declared aas integer


Expand|Select|Wrap|Line Numbers
  1. mesge = 1
  2. hello = Trim(ListView1.SelectedItem)
  3. MsgBox "Are you Sure you Want to Delete " & hello & "?", vbOKCancel, "ERROR"
Hi!

Declare mesge As String and you did't pass the MsgBox Result to the variable mesge . Use the following Code
Expand|Select|Wrap|Line Numbers
  1. Dim mesge as String
  2. mesge = MsgBox ("Are you Sure you Want to Delete " & hello & "?", vbOKCancel, "ERROR")
All The Best

With Regards
Vijay. R
Dec 29 '07 #5

100+
P: 274
its a code to remove a particularly selected ietem froam alistvieew,where 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.
Dec 29 '07 #6

Expert 5K+
P: 8,434
... 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.)
Dec 29 '07 #7

100+
P: 103
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???
Dec 31 '07 #8

debasisdas
Expert 5K+
P: 8,127
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
Dec 31 '07 #9

100+
P: 103
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
Expand|Select|Wrap|Line Numbers
  1. If mesge = vbOK Then
  2.     rs.Open "select * from empdetail where name = '" & mName & "'", conn, adOpenStatic, adLockOptimistic
  3.     Form1.txtid.Text = rs!id
  4.     Form1.txtname.Text = rs!Name
  5.     Form1.txtwhr.Text = rs!whours
  6.     Form1.txtrate.Text = rs!Rate
  7.     Form1.txtorate.Text = rs!otrate
  8.     txtid.Enabled = False
  9.     txtname.SetFocus
  10.     Form1.txtname.SetFocus
  11. else
  12.     conn.Execute "update empdetail set Name= '" & txtname & "',whours='" & txtwhrs & "',rate ='" & txtrate & "',otrate ='" & txtorate & "'"
  13.     MsgBox "UPDATED NEW DETAILS", vbOKOnly, "UPDATED RECORDS"
  14.     rs.Close
  15.     Set rs = Nothing
  16. End If
Please go through.
Dec 31 '07 #10

debasisdas
Expert 5K+
P: 8,127
what is the problem with current code ?

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

use
Expand|Select|Wrap|Line Numbers
  1. conn.begintrans
  2. conn.execute "sql update statment"
  3. conn.committrans
  4.  
Dec 31 '07 #11

100+
P: 103
what is the problem with current code ?

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

use
Expand|Select|Wrap|Line Numbers
  1. conn.begintrans
  2. conn.execute "sql update statment"
  3. conn.committrans
  4.  
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??
Dec 31 '07 #12

debasisdas
Expert 5K+
P: 8,127
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.
Dec 31 '07 #13

100+
P: 103
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""!!!
Dec 31 '07 #14

Expert 5K+
P: 8,434
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.
Jan 1 '08 #15

Post your reply

Sign in to post your reply or Sign up for a free account.