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

Code for validation.???Not working

100+
P: 103
Please go thru the code,the statement bolde d is not working,
this is for code validation.......
Code:(vb)

str = ListView1.SelectedItem
rs1.Open "select * from empdetail Where name='" & str & "'", conn, adOpenStatic, adLockOptimistic
store = rs1!id
If rs1.EOF Then
conn.Execute "insert into saldetail(id,date,othours,otamt,taxrate,netsal,pro vince)values ('" & store & "','" & dtpay & "','" & txtoh & "','" & txtotamt & "','" & txttr & "','" & txtnsal & "','" & cbostate & "')"
MsgBox "INSERTED NEW RECORDS", vbOKOnly, "ADDING NEW RECORDS"
Else
'ID Found In DB (Duplicate)
MsgBox "Already exists", vbExclamation, "ERROR"
End If
rs1.Close
Set rs1 = Nothing

PLease go thru........Thanks in advance
Dec 18 '07 #1
Share this Question
Share on Google+
18 Replies


QVeen72
Expert 100+
P: 1,445
Hi,

DONT USE "Str" as Variable name
and
Keep a Breakpoint and check if the variable is populated by the selected name, or you may have to use SubItems of the SelectedItem..

REgards
Veena
Dec 18 '07 #2

100+
P: 103
The[B] if loop [/b] is not working
code:vb
if not rs1.eof then
if we add this code too it wont work....
yes,a no corresoponding is comin in
store=rs!ID

hELP ME....thanks iN aDVANCE
Dec 18 '07 #3

Expert 5K+
P: 8,434
Could you be more specific than "not working"? That could mean anything from branching the wrong way to burning down your house. :)
Dec 18 '07 #4

QVeen72
Expert 100+
P: 1,445
Hi,

I told you to check for str = Listview.... (not Store =)

if your variable populating with List'View's Selected Item (Name)..?


Regards
Veena
Dec 18 '07 #5

100+
P: 103
That means the code is nt executing properly,hope u got the word meaning now.
The code actually executes till

code:vb
[B]if rs1.eof then
then suddenly moves to
else[/b]

Hope u understnad the situation
Dec 18 '07 #6

QVeen72
Expert 100+
P: 1,445
Hi,

I hope you changed variable name to str1

str1 = ListView1.SelectedItem

keep a breakpoint and check what is str1

Regards
Veena
Dec 18 '07 #7

100+
P: 103
Hi,

I told you to check for str = Listview.... (not Store =)

if your variable populating with List'View's Selected Item (Name)..?


Regards
Veena
Veena,
ya i have chekd that too...but thres no such variable
populating to str
but with Store,therez a variablre anfd that too populating with List'View's Selected Item (Name)..?
Dec 18 '07 #8

QVeen72
Expert 100+
P: 1,445
Hi,

if variable Store is being populated with RS("ID...").... then, Record is already present in the database table, so your "IF RS.EOF" becomes False, and INSERT Statement does not execute..


Regards
Veena
Dec 18 '07 #9

Expert 5K+
P: 8,434
That means the code is nt executing properly,hope u got the word meaning now.
The code actually executes till

code:vb
[B]if rs1.eof then
then suddenly moves to
else[/b]

Hope u understnad the situation
This simply mean that rs1.eof is not true, so VB jumps to the Else clause. Presumably there's at least one record in the recordset, so you are not at the "end of file".
Dec 18 '07 #10

100+
P: 103
This simply mean that rs1.eof is not true, so VB jumps to the Else clause. Preumsbaly there's at least one record in the recordset, so you are not at the "end of file".
No but there are atleast 10 records in the database...........
Dec 18 '07 #11

100+
P: 103
This simply mean that rs1.eof is not true, so VB jumps to the Else clause. Preumsbaly there's at least one record in the recordset, so you are not at the "end of file".
NO,there are 10 records in the record base
Dec 18 '07 #12

100+
P: 103
Hi,

if variable Store is being populated with RS("ID...").... then, Record is already present in the database table, so your "IF RS.EOF" becomes False, and INSERT Statement does not execute..


Regards
Veena

Expand|Select|Wrap|Line Numbers
  1. strName = ListView1.SelectedItem
  2. rs1.Open "select * from empdetail Where name='" & strName & "'", conn, adOpenStatic, adLockOptimistic
  3. store = rs1!id
  4. If rs1.EOF Then
  5.     conn.Execute "insert into saldetail(id,date,othours,otamt,taxrate,netsal,province)values ('" & store & "','" & dtpay & "','" & txtoh & "','" & txtotamt & "','" & txttr & "','" & txtnsal & "','" & cbostate & "')"
  6. MsgBox "INSERTED NEW RECORDS", vbOKOnly, "ADDING NEW RECORDS"
  7. Else
  8.   ' ID Found In DB (Duplicate)
  9.    MsgBox "Duplicate Entry"
  10. End If
  11. rs1.Close
  12. Set rs1 = Nothing

How come that could be veena?
Please go through the code once more.
Dec 18 '07 #13

Expert 5K+
P: 8,434
NO,there are 10 records in the record base
So what's the problem then? You opened a recordset with 10 records, and VB says it's not empty. Sounds OK to me.
Dec 18 '07 #14

100+
P: 274
Please try following:
use TRIM around strName
or
Try the same query by hardcoding a name instead & strName & "'
If it works then trim should work.
P.S.
Not sure are geting ELSE part of loop working all the time you try the code or you are getting an error message?

Good luck
Dec 18 '07 #15

QVeen72
Expert 100+
P: 1,445
Hi,


Do I Miss something here ....?

You Open a Recordset in "empDetail"
and Insert Record in "SalDetail"

rs1.Open "select * from empdetail Where name='" & strName & "'", conn, adOpenStatic, adLockOptimistic

conn.Execute "insert into saldetail(id,date,othours,otamt,taxrate,netsal,pro vince)values ('" & store & "','" & dtpay & "','" & txtoh & "','" & txtotamt & "','" & txttr & "','" & txtnsal & "','" & cbostate & "')"
...?

Regards
Veena
Dec 18 '07 #16

100+
P: 103
Hi,


Do I Miss something here ....?

You Open a Recordset in "empDetail"
and Insert Record in "SalDetail"



...?

Regards
Veena
yes yes.............
select from empdetail
and insert in saldeatil
Dec 18 '07 #17

QVeen72
Expert 100+
P: 1,445
Hi,

In that Case, You populate ListView from EmpDetails, And Always RS1 is Populated with Records from EmpDetails, So you cannot Check For RS1.EOF
Open one more recordset for salDetail and check EOF of that..
some thing like this....

Expand|Select|Wrap|Line Numbers
  1. strName = ListView1.SelectedItem
  2. rs1.Open "select * from empdetail Where name='" & strName & "'", conn, adOpenStatic, adLockOptimistic
  3. store = rs1!id
  4. Dim RS2 As New ADODB.RecordSet
  5. Set RS2 = Nothing
  6. RS2.Open "select * from Saldetail Where ID='" & Store & "'", conn, adOpenStatic, adLockOptimistic
  7. If RS2.EOF Then
  8.     conn.Execute "insert into saldetail(id,date,othours,otamt,taxrate,netsal,province)values ('" & store & "','" & dtpay & "','" & txtoh & "','" & txtotamt & "','" & txttr & "','" & txtnsal & "','" & cbostate & "')"
  9. MsgBox "INSERTED NEW RECORDS", vbOKOnly, "ADDING NEW RECORDS"
  10. Else
  11.   ' ID Found In DB (Duplicate)
  12.    MsgBox "Duplicate Entry"
  13. End If
  14. rs1.Close
  15. Set rs1 = Nothing
  16. RS2.Close
  17. Set RS2 = Nothing
  18.  

Regards
Veena
Dec 18 '07 #18

100+
P: 103
Thank you all, I got it.
I was wrong!
Dec 18 '07 #19

Post your reply

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