Creating new records within a filtered form (1 Viewer)

mrFlibble47

New member
Local time
Today, 14:24
Joined
Apr 30, 2008
Messages
4
Hello,

I have had a search through the forums before posting this and have found previous threads that touch on this area but not (yet) managed to find one that covers everything i need to know.

I have a main form with a subform - in the subform it shows records from the "Scores" table (in continuous form view) and next to each i have a command button that opens the "L&D" form showing records from the "L&D" table filtered to show those that correspond to that score.
That uses this code i found here - so far so good.

Code:
stDocName = "L&D"
stLinkCriteria = "[ScoreID]=" & Me![ScoreID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

The problem is getting the form to autopopulate various fields when you create a new record - at the moment if you create a new record all the fields are blank so anything created will not subsequently show up if you close and re-open the L&D form.

The Scores form has the fields ScoreID and EmployeeID which would need to be used to populate the fields of the same name in the L&D form when a new record is created in the (filtered) L&D form.

I hope someone can help me with this (and that i haven't been too incoherent in my explanation )
 

mrFlibble47

New member
Local time
Today, 14:24
Joined
Apr 30, 2008
Messages
4
your database is certainly doing what i want mine to do. I'll have a go at implementing the code it uses in mine. thanks.
 

mrFlibble47

New member
Local time
Today, 14:24
Joined
Apr 30, 2008
Messages
4
ok i've tried putting this in to the L&D form

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)

    If IsNull(Forms!Scores!ScoreID) Then
        MsgBox "you have to add a parent first.  "
        Me.Undo
        Cancel = True
        Exit Sub
    ElseIf IsNull(Me.ScoreID) Then
        Me.ScoreID = Forms!Scores!ScoreID
        Me.EmployeeID = Forms!Scores!EmployeeID
    End If

End Sub

but it doesn't get past the line
Code:
If IsNull(Forms!Scores!ScoreID) Then

and an error message comes up saying "run-time error '2450' - can't find the form 'Scores' referred to in the macro

Could this be because Scores isn't open on its own - it's a subform within the form 'Main' ?

EDIT: tried opening Scores on it's own and clicking the button to go into L&D which then opened but wouldn't let me create a new L&D record for that score.
 

miltiadis21

Junior Programmer
Local time
Today, 06:24
Joined
Jul 11, 2007
Messages
44
Forms!Parent!Child!Record
Or else Forms!MasterForm!ChildForm!ChildFormRecord
 

mrFlibble47

New member
Local time
Today, 14:24
Joined
Apr 30, 2008
Messages
4
thanks I think it's working ok now.

This is what i'm using:
Code:
    If IsNull(Me.EmployeeID) Then
        Me.ScoreID = Forms!Main!Child9!ScoreID
        Me.EmployeeID = Forms!Main!Child9!EmployeeID
    End If

didn't realise at first that the subform was called 'child9'

Also at the same time you were posting about "Forms!Parent!Child!Record" i had managed to find this page which is quite useful http://www.mvps.org/access/forms/frm0031.htm
 

miltiadis21

Junior Programmer
Local time
Today, 06:24
Joined
Jul 11, 2007
Messages
44
thanks I think it's working ok now.

This is what i'm using:
Code:
    If IsNull(Me.EmployeeID) Then
        Me.ScoreID = Forms!Main!Child9!ScoreID
        Me.EmployeeID = Forms!Main!Child9!EmployeeID
    End If

didn't realise at first that the subform was called 'child9'

Also at the same time you were posting about "Forms!Parent!Child!Record" i had managed to find this page which is quite useful http://www.mvps.org/access/forms/frm0031.htm
Yes i know this page i am glad that you solved it :)
 

Users who are viewing this thread

Top Bottom