943,949 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Jul 30th, 2009
0

Do until loop

Expand Post »
Good Day People
Please help me, I'm trying to do a do until loop, which can search the database to match the value that is entered in the vb6.0 textbox. but I don't know what to call the value in the database.
It looks something like this.
dim productid as integer
productid=me.productid.text
Do until productid=product_id(this is the value I don't know what to call, it is the value in the database)
PLEASE HELP.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mpande is offline Offline
21 posts
since Jun 2009
Jul 30th, 2009
0

Re: Do until loop

hi, this might give you an idea:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. num = 1 ' initialize counter
  2. 'rs is the reference to your recordset change if needed
  3. Do While Not rs.EOF
  4. ' See if the data has been found
  5. If product_id = rs!product_id Then
  6. 'do something here
  7. End If
  8.  
  9. ' If not found move to the next record.
  10. num = num + 1
  11. rs.MoveNext
  12. Loop

and just curious why you need me on this code;
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. dim productid as integer
  2. productid=me.productid.text
why not do like this:
productid=productid.text

i hope it helps..
Reputation Points: 19
Solved Threads: 115
Nearly a Posting Virtuoso
cguan_77 is offline Offline
1,317 posts
since Apr 2007
Jul 30th, 2009
0

Re: Do until loop

if it is a specific item you are looking for why search through mulitple records?

vb Syntax (Toggle Plain Text)
  1. sSQL = "Select fields from table where id = " & productid & "
  2.  

then you can run your do while.
Last edited by ProfessorPC; Jul 30th, 2009 at 8:24 pm.
Reputation Points: 31
Solved Threads: 29
Posting Whiz in Training
ProfessorPC is offline Offline
270 posts
since Dec 2007
Jul 31st, 2009
0

Re: Do until loop

or if it is a partial product id no then...

"Select * from table where productid like '" & sometext & "*'"

if it is text or if not remove the single ticks (')


Good Luck
Reputation Points: 156
Solved Threads: 296
Posting Virtuoso
vb5prgrmr is offline Offline
1,670 posts
since Mar 2009
Aug 13th, 2009
0

Re: Do until loop

Click to Expand / Collapse  Quote originally posted by cguan_77 ...
hi, this might give you an idea:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. num = 1 ' initialize counter
  2. 'rs is the reference to your recordset change if needed
  3. Do While Not rs.EOF
  4. ' See if the data has been found
  5. If product_id = rs!product_id Then
  6. 'do something here
  7. End If
  8.  
  9. ' If not found move to the next record.
  10. num = num + 1
  11. rs.MoveNext
  12. Loop

and just curious why you need me on this code;
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. dim productid as integer
  2. productid=me.productid.text
why not do like this:
productid=productid.text

i hope it helps..
Thanks for your help Cguan
But it still won't work have been at it, trying to find the problem but to no avail, is it not possible to reference a variable in VB6.0 to a variable in oracle database. Because thats all I need.
Do until productid(vb6.0)=productid(database)-this is the problem
if productid(vb6.0)=productid(database) then
do something
loop
end if
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mpande is offline Offline
21 posts
since Jun 2009
Aug 13th, 2009
0

Re: Do until loop

what are you using to connect to the DB? i am guessing something like this:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim cn As ADODB.Connection
  2. Dim rs As ADODB.Recordset
  3.  
  4. Set cn = New ADODB.Connection
  5. cn.Open 'connection string
  6. Set rs = New ADODB.Recordset
  7. rs.Open "Select fields from table where id = " & productid.text & "", cn
  8. While Not rs.EOF
  9. do something
  10. rs.MoveNext
  11. rs.Close
  12. Set rs = Nothing
  13. cn.Close
  14. Set cn = Nothing
Last edited by ProfessorPC; Aug 13th, 2009 at 10:02 am.
Reputation Points: 31
Solved Threads: 29
Posting Whiz in Training
ProfessorPC is offline Offline
270 posts
since Dec 2007
Aug 14th, 2009
0

Re: Do until loop

what are you using to connect to the DB? i am guessing something like this:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim cn As ADODB.Connection
  2. Dim rs As ADODB.Recordset
  3.  
  4. Set cn = New ADODB.Connection
  5. cn.Open 'connection string
  6. Set rs = New ADODB.Recordset
  7. rs.Open "Select fields from table where id = " & productid.text & "", cn
  8. While Not rs.EOF
  9. do something
  10. rs.MoveNext
  11. rs.Close
  12. Set rs = Nothing
  13. cn.Close
  14. Set cn = Nothing
Thanks For your help, Proffessor PC.
I think it works, but won't see that properly now because it gives an error later on when I say: if productid=rs!product_id then
rs.open"select fields from table", "update field set data"
but it gives me an error on open(wrong number of arguments or invalid property assignment), could you please help, i have also tried .execute instead of .open, but it gives me the same error message.
Please help!!!!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mpande is offline Offline
21 posts
since Jun 2009
Aug 15th, 2009
0

Re: Do until loop

Click to Expand / Collapse  Quote originally posted by mpande ...
Thanks For your help, Proffessor PC.
I think it works, but won't see that properly now because it gives an error later on when I say: if productid=rs!product_id then
rs.open"select fields from table", "update field set data"
but it gives me an error on open(wrong number of arguments or invalid property assignment), could you please help, i have also tried .execute instead of .open, but it gives me the same error message.
Please help!!!!
hi mpande, the code that Proffessor PC gives you it seems to work fine.. so maybe you can post the code that you try
Last edited by cguan_77; Aug 15th, 2009 at 3:30 am.
Reputation Points: 19
Solved Threads: 115
Nearly a Posting Virtuoso
cguan_77 is offline Offline
1,317 posts
since Apr 2007
Aug 17th, 2009
0

Re: Do until loop

Click to Expand / Collapse  Quote originally posted by cguan_77 ...
hi mpande, the code that Proffessor PC gives you it seems to work fine.. so maybe you can post the code that you try
Hi cguan the code that I'm using is this:
If productid = rs!product_id Then
Set updatedb = New ADODB.Connection
updatedb.Open "DSN=waterdb;Password=andile;User ID=eco;Data Source=waterdb"
Set rs1 = New ADODB.Recordset
rs1.Open "Select product_id,qty,stock_date,trans_type,qtydb from stock", "update stock set product_id=productid", "update stock set qty=qty", "update stock set stock_date=date", "update stock set trans_type=trans_type", "update stock set qtydb=qtydb"
With Adodc1
.Recordset.Update
.Recordset.Fields("product_id") = productid
.Recordset.Fields("qty") = qty
.Recordset.Fields("stock_date") = dop
.Recordset.Fields("trans_type") = "trans_type"
.Recordset.Fields("qtydb") = qtydb

End With

Else: MsgBox ("invalid product id")
End If
db.CommitTrans
rs.MoveNext
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
Loop

But the problem is at rsi.open, it gives me an error saying-wrong number of arguments or invalid property assignment.
Please help!!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mpande is offline Offline
21 posts
since Jun 2009
Aug 17th, 2009
0

Re: Do until loop

Click to Expand / Collapse  Quote originally posted by mpande ...
Hi cguan the code that I'm using is this:
If productid = rs!product_id Then
Set updatedb = New ADODB.Connection
updatedb.Open "DSN=waterdb;Password=andile;User ID=eco;Data Source=waterdb"
Set rs1 = New ADODB.Recordset
rs1.Open "Select product_id,qty,stock_date,trans_type,qtydb from stock", "update stock set product_id=productid", "update stock set qty=qty", "update stock set stock_date=date", "update stock set trans_type=trans_type", "update stock set qtydb=qtydb"
With Adodc1
.Recordset.Update
.Recordset.Fields("product_id") = productid
.Recordset.Fields("qty") = qty
.Recordset.Fields("stock_date") = dop
.Recordset.Fields("trans_type") = "trans_type"
.Recordset.Fields("qtydb") = qtydb

End With

Else: MsgBox ("invalid product id")
End If
db.CommitTrans
rs.MoveNext
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
Loop

But the problem is at rsi.open, it gives me an error saying-wrong number of arguments or invalid property assignment.
Please help!!
okay lets see what we can do lol. so you get the data from the product id. you are updating the table with the values in txt boxes? if that is the way your are working it lets try this.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. rs1.Open "UPDATE Stock (qty, stock_date, trans_type, qtydb ) Values (" & qtyfield &", " & stock_datefield &", " & trans_type &", " & qtydbfield &")", updatedb

been a long day hope that works lol
Reputation Points: 31
Solved Threads: 29
Posting Whiz in Training
ProfessorPC is offline Offline
270 posts
since Dec 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Pyramid Issue
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: cells.find in excel





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC