Creating Records in a Continuous SubForm Automatically

C

chrisc

Hello,

I'm having some trouble with this.

I have database that I'm working on which will log faults found on
circuit boards that are tested in batches.

Tables:

'Batch' Linked to 'Product' Linked to 'Faults'

What I want to happen on my form is that the user will enter a number
into an unbound field called 'Autonum' they will then press a button
which will automatically add records into the Faults Subform.

It will also add a number for as many records as it needs into a field
called 'Serial Number'

For Instance

15 Records:

Fault_Description ¦ Serial Number ¦ Pass / Fail

blah 1 x
blah 2 x
blah 3 x

etc.

The code I have on the button that the user would click is as follows,
but I'm damned if I can get it to work, the futherst I've got is to an
error saying you cant enter these records as a record in 'Products' is
required.

Dim mydb As Database, rs As Recordset, x As Integer
Set rs = mydb.OpenRecordset("Faults", dpOpenDynaset, dbAppendOnly)

For x = 1 To Me!AutoNum
rs.AddNew
rs("Serial Number") = x
rs("Fault_ID") = "PrimaryKey"
rs.Update
Next x

rs.Close
Set rs = Nothing

This code actually falls down on the 2nd line with a block not set
error, however I have also had runtime errors at various stages when
I've been playing around.

Can anyone help me, or let me know where I'm going wrong? I have tried
this button and number field on both the main, and Faults subform..

Many thanks,

Chris.
 

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