Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > simple loop with access


Reply
 
Thread Tools Display Modes
  #1  
Old 04-14-2003, 11:58 AM
xelonite84 xelonite84 is offline
Junior Contributor
 
Join Date: Apr 2003
Location: manchester
Posts: 305
Default simple loop


i want a loop that will go through a database so once the user clicks on the "check" button it will check all of the entries for the pay rate being less than 30 if the pay is more than 30 then an error message will apear and the cursor will go to that text box in order for the user to update it

ive tried a few ways including these:

PHP Code:
  If TxtPay 30 Then DatPay.Recordset.MoveNext
       
Else: MsgBox "error" 
txtpay.setfocus

    End 
If
   
   
If 
TxtPay 30 Then Exit Do
    Else: 
MsgBox "error"
txtpay.setfocus
  Loop 
could anyone suggest how i could get this to work please?

cheers
Reply With Quote
  #2  
Old 04-14-2003, 12:07 PM
Iceplug's Avatar
Iceplug Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
Default

Is the data already in the database or in the form.
If it's on the form, then it'd be best if you had a control array and looped through that.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #3  
Old 04-14-2003, 12:10 PM
xelonite84 xelonite84 is offline
Junior Contributor
 
Join Date: Apr 2003
Location: manchester
Posts: 305
Default

no the information is in an access database
Reply With Quote
  #4  
Old 04-14-2003, 12:13 PM
Robse's Avatar
Robse Robse is offline
Senior Contributor

* Expert *
 
Join Date: Sep 2002
Location: Karlsruhe, Germany
Posts: 1,319
Default

Also it would be better if you convert the
string from the textbox into a number like this:

Code:
If Val(TxtPay.Text) < 30

before you do a comparison with another number.

Using Iceplug's suggestion of a control array for
your textboxes will change it into something like this:
Code:
If Val(TxtPay(Index).Text) < 30
__________________
Posting Guidelines MSDN-VB API List Use [vb]...[/vb] tags for code!
Reply With Quote
  #5  
Old 04-14-2003, 12:19 PM
xelonite84 xelonite84 is offline
Junior Contributor
 
Join Date: Apr 2003
Location: manchester
Posts: 305
Default simple loop with access

i want a loop that will go through a database so once the user clicks on the "check" button it will check all of the entries for the pay rate being less than 30 if the pay is more than 30 then an error message will apear and the cursor will go to that text box in order for the user to update it

ive tried a few ways including these:

Code:
If TxtPay < 30 Then DatPay.Recordset.MoveNext Else: MsgBox "error" End If If TxtPay < 30 Then Exit Do Else: MsgBox "error" Loop

does anyone have any suggestions on how i could get this to work?

cheers
Reply With Quote
  #6  
Old 04-14-2003, 12:24 PM
khamel khamel is offline
Newcomer
 
Join Date: Jul 2002
Location: Iowa
Posts: 13
Default

cheers[/QUOTEPOST]
have you tried
do while txtpay (not sure how to get this part right) .text =! " "
if Val(txtpay) < 30 then
datpay.recordset.movenext
else
msgbox "error"
end if
loop

Sorry about the first line i am checking in my post how to do this but in theory this should work
Cassie
__________________
Khamel
Reply With Quote
  #7  
Old 04-14-2003, 12:24 PM
xelonite84 xelonite84 is offline
Junior Contributor
 
Join Date: Apr 2003
Location: manchester
Posts: 305
Default

that wouldnt make it work tho would it? doesnt that just improve the code in some way?

do you know where i am going wrong with my code ? or is it all wrong? i dont think it is but im not all that brilliant with vb. web programming is more my area
Reply With Quote
  #8  
Old 04-14-2003, 12:52 PM
reboot's Avatar
reboot reboot is offline
Keeper of foo

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Graceland
Posts: 15,612
Default

Why not just start with the recordset containing all the entries that are more than 30? Then you simply loop through that recordset, as it already contains all the records you want to change, and none of the ones you don't.
Reply With Quote
  #9  
Old 04-14-2003, 12:57 PM
xelonite84 xelonite84 is offline
Junior Contributor
 
Join Date: Apr 2003
Location: manchester
Posts: 305
Default

because there is more than 1 person who can add entries to the database although this isnt doen through the program so i need the program to just check all entries for any errors
Reply With Quote
  #10  
Old 04-14-2003, 01:03 PM
reboot's Avatar
reboot reboot is offline
Keeper of foo

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Graceland
Posts: 15,612
Default

Uhhhh.... ok.
Reply With Quote
  #11  
Old 04-14-2003, 01:05 PM
xelonite84 xelonite84 is offline
Junior Contributor
 
Join Date: Apr 2003
Location: manchester
Posts: 305
Default

ok that might make no sense but no i cant do that

is there no way that will just search all the entries until it comes across that field with a number equal to or over 30? then puts the curser in that field so the user can change it?
Reply With Quote
  #12  
Old 04-14-2003, 01:09 PM
Robse's Avatar
Robse Robse is offline
Senior Contributor

* Expert *
 
Join Date: Sep 2002
Location: Karlsruhe, Germany
Posts: 1,319
Default

Quote:
Originally Posted by xelonite
i want a loop that will go through a database so once the user clicks on the "check" button it will check all of the entries for the pay rate being less than 30 if the pay is more than 30 then an error message will apear and the cursor will go to that text box in order for the user to update it



So you have multiplie textboxes? And by "entries" you mean the entries
in the textboxes? And you always want to check if they are less than
30? Or am I misunderstanding something.
__________________
Posting Guidelines MSDN-VB API List Use [vb]...[/vb] tags for code!
Reply With Quote
  #13  
Old 04-14-2003, 01:12 PM
xelonite84 xelonite84 is offline
Junior Contributor
 
Join Date: Apr 2003
Location: manchester
Posts: 305
Default

ive tried that and a few variations including:

Code:
Do While Val(TxtPay.Text) = " " If Val(TxtPay) < 30 Then DatPay.Recordset.MoveNext Else MsgBox "error" TxtPay.SetFocus End If Loop

and
Code:
Do While Val(TxtPay.Text) = " " If Val(TxtPay) < 30 Then DatPay.Recordset.MoveNext Else MsgBox "error" End If Loop
aswel as a few others but i still cant get it to work
Reply With Quote
  #14  
Old 04-14-2003, 01:14 PM
xelonite84 xelonite84 is offline
Junior Contributor
 
Join Date: Apr 2003
Location: manchester
Posts: 305
Default

i do have multiple text boxes and yes the user does enter them on the program but there is also a lot of entries in the database that i want the program to check
Reply With Quote
  #15  
Old 04-14-2003, 01:53 PM
Robse's Avatar
Robse Robse is offline
Senior Contributor

* Expert *
 
Join Date: Sep 2002
Location: Karlsruhe, Germany
Posts: 1,319
Default

Quote:
Originally Posted by xelonite
i do have multiple text boxes and yes the user does enter them on the program but there is also a lot of entries in the database that i want the program to check



Yes but I think it would be easier to first do one thing, then
the other. So do you want to make sure that all textboxes contain
values < 30 first or do you want to compare the textbox values to those
in the database first?

(BTW You really don't need the database to make sure each textbox's
value is smaller than a given number)
__________________
Posting Guidelines MSDN-VB API List Use [vb]...[/vb] tags for code!
Reply With Quote
  #16  
Old 04-14-2003, 01:59 PM
xelonite84 xelonite84 is offline
Junior Contributor
 
Join Date: Apr 2003
Location: manchester
Posts: 305
Default

i want to make sure not all the text boxes just txtpay contains a number less than 30
Reply With Quote
  #17  
Old 04-14-2003, 02:13 PM
Robse's Avatar
Robse Robse is offline
Senior Contributor

* Expert *
 
Join Date: Sep 2002
Location: Karlsruhe, Germany
Posts: 1,319
Default

OK. But doesn't the code that you posted do just that?

Code:
Private Sub Command1_Click() If Val(txtPay.Text) < 30 Then 'Everything OK, database & Exit code here DatPay.Recordset.MoveNext Exit Do Else MsgBox "Error! txtPay >= 30 !!!" txtPay.SetFocus End If End Sub

P.S. I got a little confused because you used PHP tags!
__________________
Posting Guidelines MSDN-VB API List Use [vb]...[/vb] tags for code!
Reply With Quote
  #18  
Old 04-14-2003, 02:20 PM
DRW DRW is offline
Junior Contributor
 
Join Date: Aug 2002
Location: England
Posts: 308
Default

Have you tried FindFirst/FindNext Or Seek?
Reply With Quote
  #19  
Old 04-14-2003, 02:28 PM
xelonite84 xelonite84 is offline
Junior Contributor
 
Join Date: Apr 2003
Location: manchester
Posts: 305
Default

no the code i used just tested the txtpay text box

that code came up with an error:
compile error

Exit Do not within Do...Loop
Reply With Quote
  #20  
Old 04-14-2003, 02:37 PM
Robse's Avatar
Robse Robse is offline
Senior Contributor

* Expert *
 
Join Date: Sep 2002
Location: Karlsruhe, Germany
Posts: 1,319
Default

Quote:
Originally Posted by xelonite
i want to make sure not all the text boxes just txtpay contains a number less than 30



Quote:
Originally Posted by xelonite
no the code i used just tested the txtpay text box



??? I'm confused. Did you try the code that I posted?

Edit: Might also be a good idea if you posted your whole
code (if it's not too long).
__________________
Posting Guidelines MSDN-VB API List Use [vb]...[/vb] tags for code!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Standards and Practices loquin Tutors' Corner 10 07-28-2006 12:16 PM
Simple loop question....:D Tuskony General 10 10-29-2002 08:59 PM
simple loop question acromi General 4 10-09-2002 01:00 PM
Simple access question..please help! james_j Database and Reporting 1 09-11-2001 02:45 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->