New Record

Xenix

Registered User.
Local time
Today, 18:23
Joined
Oct 8, 2001
Messages
124
Hi,

I want to click a button on my main form and for it to create as many records as there are tray numbers. The main form is called WorkOrderDetails and the sub form is TrayDetails1

The code I have tried using is:Dim x As Integer
x = 0

For x = 0 To Forms!workorderdetails!TrayDetails1!Total
x = x + 1
Forms!workorderdetails!TrayDetails1!NumberofTrays = x
DoCmd.GoToRecord , Forms!workorderdetails!TrayDetails1, acNewRec
Next

But this will not work I guess because the TrayDetails1 subform is not the active form :( can anyone help me?
 
I'm not sure if your code will create multiple records on the subform in this way, but you need to set focus to the subform first
 
Set Focus

Thank you Rich,

but if I try and set the focus to that subform with the code:Forms!workorderdetails!TrayDetails1!Total.SetFocus

I get an error message box:

Out worker database can't move the focus to the control Total


any ideas?
 
Replace this line

Forms!workorderdetails!TrayDetails1!NumberofTrays = x

with this

Me.TrayDetails1.SetFocus
Docmd.GoToControl "NumberofTrays"


Here's what Access Help suggests.


Tip You can use the SetFocus method to move the focus to a subform, which is a type of control. You can also move the focus to a control on a subform by using the SetFocus method twice, moving the focus first to the subform and then to the control on the subform.
 
Thank you Tim,

I have used the following code:
Dim x, p As Integer
Dim trays As Integer

x = 0
trays = Forms!workorderdetails!NumberofTrays

Forms!workorderdetails!TrayDetails1.SetFocus

For x = 0 To trays
x = x + 1
Forms!workorderdetails!TrayDetails1!NumberofTrays = x
DoCmd.GoToRecord , , acNewRec
For p = 0 To 10000
p = p + 1
Next
Next

The second For loop was for a delay, the problem is now this has started to work but it only creates a record for every other number? e.g. 1,3,5

Very strange I can't see anything wrong in my For loop so must just have to slow down the function: docmd.gotorecord , , acNewRec

any ideas would be great
Thank you

Mike
 
Fixed it

Ok everyone I done it :)

If anyone else wants to use this idea please feel free the trick was a Do..While

Dim x, p, q As Integer
Dim trays As Integer

x = 0
trays = Forms!workorderdetails!NumberofTrays

Forms!workorderdetails!TrayDetails1.SetFocus

Do While x <> trays
x = x + 1
Forms!workorderdetails!TrayDetails1!NumberofTrays = x
DoCmd.GoToRecord , , acNewRec
Loop

Works 100% perfect, thank you for all your help

Mike
 

Users who are viewing this thread

Back
Top Bottom