Entering a multiple number of records based on a quantity in text box

R

RMTechie

Is there a way to enter a quantity of records equal to a number in a
text box?

For instance,

Let's say I have a:

Combo box with the options: Breakfast, Lunch, Dinner
Text box with date
Text box with the number of records I want entered
Command button to add records

The record would have only the date and meal type as fields.

I want to let the user select a meal type, give the number of records
(people) and click the button and add a record for each. For various
reasons, I can't just have a total quantity for that date, I need
separate records.

Any help?
 
D

Dale Fye

Keeping Linq's motto: There's ALWAYS more than one way to skin a cat!
in mind, I would do this with another technique.

1. I have a table in almost every one of my databases (tbl_Numbers) which
contains a single field lngNumber, and ten values (the numbers 0 to 9).
2. I also have a query that goes with it (qry_Numbers) that generates the
numbers from 0 to 99 (it is easy to expand this to 999 or 9999 based on your
needs) that looks like:

SELECT Tens.lngNumber * 10 + Ones.lngNumber as lngNumber
FROM tbl_Numbers as Tens, tbl_Numbers as Ones

3. In the command button that generates the records (cmdMultiCopy) I would
put code similar to:

Private Sub cmdMultiCopy_Click

Dim strSQL as string

On Error goto AddRecError
strSQL = "INSERT INTO tbl_yourTable (DateFieldName, MealFieldName) " _
& "SELECT DateAdd('d', lngNumber, #" & mt.txtDateField & "#, " _
& me.cbo_MealType & ") "
& "FROM qryNumbers " _
& "WHERE lngNumber < " & me.txtNumberOfRecords
Currentdb.Execute strSQL, dbFailOnError
Exit Sub

AddRecError:
msgbox err.number & vbcrlf & err.description

End Sub

--
HTH
Dale

Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.
 

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