For Loop

D

DS

I need this to run until it equales the value of Me.TxtDisplay...However
I can't get the syntax down correctly, the first line seems to be the
problem...any help appreciated.
Thanks
DS

Dim Sep As Integer
For Sep = Me.TxtDisplay <<<<<PROBLEM LINE

Forms!frmFXSeperateChecks!TxtChkAlias =
Forms!frmFXSeperateChecks!TxtChkAlias & "A"
'ADD NEW CHECKID
Forms!frmFXSeperateChecks!TxtCheckID = Nz(DMax("[CheckID]",
"tblChecks"), 0) + 1
CurrentDb.Execute "INSERT Into
tblChecks(CheckID,ChkCustomerID,ChkServer,TabID,ChkGuests,ChkTaxCodeID,ChkTypeID,ChkSepCheck,ChkOldCheckID,ChkAlias)
" & _
"VALUES('" & Forms!frmFXSeperateChecks.TxtCheckID & "'," &
Forms!frmFXSeperateChecks!TxtCustomerID & "," &
Forms!frmFXSeperateChecks!TxtServerID & "," &
Forms!frmFXSeperateChecks!TxtTabID & ",1," &
Forms!frmFXSeperateChecks!TxtTaxCodeID & ",1,True," &
Forms!frmFXSeperateChecks!TxtCheckID & ",'" &
Forms!frmFXSeperateChecks!TxtChkAlias & "')"

Next Sep
 
K

Ken Snell \(MVP\)

Syntax for the For statement is this:
For VariableName = InitialValue To FinalValue Step IncrementValue

(Default value for IncrementValue is +1.)

So, you need to tell the code what the starting value for Sep is going to
be. Assuming you want to start with zero:
For Sep = 0 To Me.TxtDisplay
 
G

Guest

Is Sep a counter to loop thru the code a given number of times? and then
txtDisplay the max number?
If so;
Sep = "0" '<< after Dim Sep as Integer

Then replace;
For Sep = Me.TxtDisplay <<<<<PROBLEM LINE
with;
Do Until Sep = Me.TxtDislay

and replace;
Next Sep
with;
Sep = Sep +1
Loop

PS For (Each)/Next loops through a collection of items eg varitems in a
listbox or recordset, Do/Loop's are for evaluating against values or value
expressions, booleans etc But always remember your Sep = Sep +1 line
otherwise you have and endless loop!!!

TonyT..
 
D

DS

Ken said:
Syntax for the For statement is this:
For VariableName = InitialValue To FinalValue Step IncrementValue

(Default value for IncrementValue is +1.)

So, you need to tell the code what the starting value for Sep is going to
be. Assuming you want to start with zero:
For Sep = 0 To Me.TxtDisplay
Thanks Ken,
So I tried this,

Dim Sep As Integer
For Sep = Me.TxtDisplay To 0 -1
Code....Blah,Blah,Blah..
Next Sep
Nothing happens...
I want to run it the number thats in Me.TxtDisplay, incrementing by -1
untill it reaches 0 and then stops.
Thanks
DS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Correct Syntax 2
Not Updating 9
SQL and Null 10
Loop and Insert Problem 5
Loop Question 2
Loop Problem 5
SQL HANGS 1

Top