simple loop with access

xelonite84
04-14-2003, 12:58 PM
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:

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

Iceplug
04-14-2003, 01:07 PM
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. :)

xelonite84
04-14-2003, 01:10 PM
no the information is in an access database

Robse
04-14-2003, 01:13 PM
Also it would be better if you convert the
string from the textbox into a number like this:


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:

If Val(TxtPay(Index).Text) < 30

xelonite84
04-14-2003, 01:19 PM
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:

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

khamel
04-14-2003, 01:24 PM
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

xelonite84
04-14-2003, 01:24 PM
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

reboot
04-14-2003, 01:52 PM
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.

xelonite84
04-14-2003, 01:57 PM
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

reboot
04-14-2003, 02:03 PM
Uhhhh.... ok.

xelonite84
04-14-2003, 02:05 PM
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?

Robse
04-14-2003, 02:09 PM
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.

xelonite84
04-14-2003, 02:12 PM
ive tried that and a few variations including:

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

End If
Loop

and
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

xelonite84
04-14-2003, 02:14 PM
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

Robse
04-14-2003, 02:53 PM
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)

xelonite84
04-14-2003, 02:59 PM
i want to make sure not all the text boxes just txtpay contains a number less than 30

Robse
04-14-2003, 03:13 PM
OK. But doesn't the code that you posted do just that?


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!

DRW
04-14-2003, 03:20 PM
Have you tried FindFirst/FindNext Or Seek?

xelonite84
04-14-2003, 03:28 PM
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

Robse
04-14-2003, 03:37 PM
i want to make sure not all the text boxes just txtpay contains a number less than 30


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).

xelonite84
04-14-2003, 03:44 PM
Private Sub cmdDelete_Click()
DatPay.Recordset.Delete
DatPay.Recordset.MovePrevious
If DatPay.Recordset.BOF Then
DatPay.Recordset.MoveFirst
End If
End Sub


Private Sub CmdExit_Click()
Unload Me
End Sub


Private Sub CmdPrint_Click()
FrmPayslip.Hide
FrmPayslip.PrintForm
FrmPayslip.Show

End Sub

Private Sub cmdUpdate_Click()
DatPay.UpdateRecord
End Sub

Private Sub cmdAdd_Click()
DatPay.Recordset.AddNew

End Sub

Private Sub CmdNext_Click()

If Val(TxtPay.Text) < 30 Then
'Everything OK, database & Exit code here
DatPay.Recordset.MoveNext
Exit Do
Else
MsgBox "Error!"
TxtPay.SetFocus
End If

End Sub

Private Sub cmdPrevious_Click()
DatPay.Recordset.MovePrevious
If DatPay.Recordset.BOF Then
DatPay.Recordset.MoveFirst
End If

End Sub

Robse
04-14-2003, 04:02 PM
OK I assumed you had a loop in your code.
Just remove the


Exit Do

xelonite84
04-14-2003, 04:33 PM
ok cheers

but what would i need to change in order to make it a loop?

Robse
04-14-2003, 04:44 PM
Depends on what you mean by "it".

Edit: Rephrase this:


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


You say there is one txtPay that you want to check, but in that
paragraph you are saying "all of the entries for the pay rate" ?
Also how does the database fit into this?

xelonite84
04-14-2003, 04:51 PM
the cmdNext button

xelonite84
04-14-2003, 05:28 PM
my database stores the information

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum