loop

N

nhdee

I have an unbound field on a (page in a ) form where the user enters the qty
they want. That field is named GroupQty. I need to loop until that qty....
but I am not sure of the real coding to accomplish this.

Do until = Me!GroupQty ('This is the qty in the unbound field that the user
enters)
Me!Type = "3-GK and 1-MG" ('fills in the type field with this)
Me!Price = "20.00" ('fills in the price field with this)
DoCmd.GoToRecord , , acNewRec ('creates a new record)
Loop
End Sub
 
B

Beetle

You want to loop and do what, exactly?

It appears you are attempting to add that many new records to your
table. What if the user mistakenly enters the wrong number but
doesn't realize it? Or they enter too large a number (like 100 instead
of 10)? You could have a real mess on your hands!

Maybe I'm misunderstanding what you are attempting. Perhaps you
could explain further.
 
B

Beetle

You want to loop and do what, exactly?

It appears you are attempting to add that many new records to your
table. What if the user mistakenly enters the wrong number but
doesn't realize it? Or they enter too large a number (like 100 instead
of 10)? You could have a real mess on your hands!

Maybe I'm misunderstanding what you are attempting. Perhaps you
could explain further.
 
N

nhdee

Thanks for replying, you are absolutely correct but it is what I need. Hope
this helps:

My database creates "tickets" so I need one ticket to print say 23 times
(the number the user inputs into the GroupQty field) . I have it working
(see code to follow) when I have assigned the number of tickets but not quite
sure how to do it when the user assigns the # of tickets. What I am using
(and works) when I know the # of tickets is say 4 for type Corporate:

Private Sub Corp4_Click()
a = 1
Do While a < 5
Me!Type = "Corporate"
Me!Price = "700.00"
DoCmd.GoToRecord , , acNewRec
a = a + 1
Loop
End Sub
 
N

nhdee

Thanks for replying, you are absolutely correct but it is what I need. Hope
this helps:

My database creates "tickets" so I need one ticket to print say 23 times
(the number the user inputs into the GroupQty field) . I have it working
(see code to follow) when I have assigned the number of tickets but not quite
sure how to do it when the user assigns the # of tickets. What I am using
(and works) when I know the # of tickets is say 4 for type Corporate:

Private Sub Corp4_Click()
a = 1
Do While a < 5
Me!Type = "Corporate"
Me!Price = "700.00"
DoCmd.GoToRecord , , acNewRec
a = a + 1
Loop
End Sub
 
J

John W. Vinson

My database creates "tickets" so I need one ticket to print say 23 times
(the number the user inputs into the GroupQty field) .

Don't confuse data STORAGE with data DISPLAY!

You do *not* need 23 records stored in your table to print 23 tickets.

What you can do is create a little general-purpose Num table with one field N,
manually filled with integer values from 1 to 10000 (or 100000, or "enough").

You can create a query with your table containing the information to be
printed on the ticket, and include this Num table with *no* join line. Put a
criterion on N of

< [GroupQty]

and it will generate 23 (GroupQty actually) copies of your table's record. Use
this query as the recordsource for your report.

You can display a ticket number on the report with a textbox with a control
source

=[N]+1

and even include GroupQty if you want to show "Ticket 11 of 23".
 
J

John W. Vinson

My database creates "tickets" so I need one ticket to print say 23 times
(the number the user inputs into the GroupQty field) .

Don't confuse data STORAGE with data DISPLAY!

You do *not* need 23 records stored in your table to print 23 tickets.

What you can do is create a little general-purpose Num table with one field N,
manually filled with integer values from 1 to 10000 (or 100000, or "enough").

You can create a query with your table containing the information to be
printed on the ticket, and include this Num table with *no* join line. Put a
criterion on N of

< [GroupQty]

and it will generate 23 (GroupQty actually) copies of your table's record. Use
this query as the recordsource for your report.

You can display a ticket number on the report with a textbox with a control
source

=[N]+1

and even include GroupQty if you want to show "Ticket 11 of 23".
 
T

tina

if your code is working as desired, and you only wish to replace the
hard-coded value 5 with a variable value, then just ask the user how many
and assign the value to a variable, as

Dim i As Integer, a As Integer

i = InputBox("How many tickets do you want?") + 1
a = 1
Do While a < i

etc, etc. if you've provided a textbox control on a form, for the user to
enter the number, then refer to that instead of using an InputBox, as

i = Me!NameOfControl + 1

hth
 
T

tina

if your code is working as desired, and you only wish to replace the
hard-coded value 5 with a variable value, then just ask the user how many
and assign the value to a variable, as

Dim i As Integer, a As Integer

i = InputBox("How many tickets do you want?") + 1
a = 1
Do While a < i

etc, etc. if you've provided a textbox control on a form, for the user to
enter the number, then refer to that instead of using an InputBox, as

i = Me!NameOfControl + 1

hth
 
N

nhdee

THANK YOU!!!! I kept the input box I had on the form instead of prompting
with a question but it works great. I so appreciate your help - Yeah!
 
N

nhdee

THANK YOU!!!! I kept the input box I had on the form instead of prompting
with a question but it works great. I so appreciate your help - Yeah!
 
T

tina

you're welcome :)


nhdee said:
THANK YOU!!!! I kept the input box I had on the form instead of prompting
with a question but it works great. I so appreciate your help - Yeah!
 
T

tina

you're welcome :)


nhdee said:
THANK YOU!!!! I kept the input box I had on the form instead of prompting
with a question but it works great. I so appreciate your help - Yeah!
 

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

Top