Specific number of blank new record

nofar

Registered User.
Local time
Today, 09:19
Joined
Jun 8, 2011
Messages
14
Hi,

I don't know if this is possible but iam trying to build a form in which I enter a number for example 10 (in a text box) and then it gives me 10 blank rows so that I can write a new record in each row.

Is it possible? or I just forget completly about this idea

Thank you so much for your help
 
It depends whether any fields are required and what kind of field the primary key is.

I've never tried but I think, if the primary key is an autonumber field and no other fields are required, you could:

Code:
Dim rsMe As Recordset
Set rsMe = Me.Recordset
With rsMe
    Dim i As Integer
    For i = 1 to 10
        .AddNew
        .Update
    Next i
End With

I have just tried and it works
 
where can I out this code in a new module or in the on load event of the form?
 
I also need the form to be a data entry form so the old records will not appear.
In this form I just have one field which is a primary key (it s a serial number).

Thank you for your help
 
Answer to first question: In a button's click event - you don't want it happening except when the user really wants it to

Answer to second question: It won't work with data entry form. You'd have to somehow filter out previous records - presumably by finding the largest ID and filtering anything less than or equal to it. The ten new records won't get filtered because they'd have larger IDs
 
I copied your code in the on click event of te button in the form "Year and WW1" but I keeps giving me an error on the .update line.
I attached the Database If you want to see it .

Thank you, I appreciate it
 

Attachments

SERIAL_NUMBER isn't an autonumber, it's text. You're going to need to assign values to it for it to accept a new record and allow another new record.

Then there's the issue of cancelling the X new records: Facility to delete them if the user changes their mind.
 
Thank you so much for your help,

I have one last question:

In the form "number" I want all the serial number that I add using the command button, in which I added the code, to have the same PO REC and SKU but this is not working
Let's say when I open 2 blank fields and I enter two Serial Number they will have empty PO REC and SKU numbers in the table "Serial Number" I don't understand why. :(

I attached the modified Database
 

Attachments

Yeah, I would've thought it would fill them in (if the parent form has values).

To force it to (and prevent errors if user types non-numbers in Text20) change the code to this:

Code:
Private Sub Command17_Click()
    If IsNumeric(Me.Text20) Then
         Dim iX As Integer
         iX = CInt(Me.Text20)
         If iX > 0 Then
             Dim rsMe As Recordset
             Set rsMe = Me.Recordset
             With rsMe
                 Dim i As Integer
                 For i = 1 To iX
                     .AddNew
                     !PO = Me.Parent!PO
                     !REC = Me.Parent!REC
                     !SKU = Me.Parent!SKU
                     .Update
                 Next i
             End With
         End If
    End If
End Sub

Also, make the new autonumber field in table SerialNumber the primary key. It currently doesn't have one, which isn't good.

And I'd recommend naming the controls something more informative than Text20 and Command17. It might seem like a waste of time until you start to put more buttons and then you have to work out which one's which by the code in their events.
 

Users who are viewing this thread

Back
Top Bottom