Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create new record based on values in 2nd form? 2

Status
Not open for further replies.

bud31047

Technical User
Dec 3, 2007
44
US
In Access97, I have a form [FilterFrm] with two fields, [DBDate] & [DBShift], that I am using to apply a filter on a 2nd form [RecordsFrm], which includes fields [wrkdate] and [shift]. This method of filtering records works fine for my purposes.

What I want to do is give the user the option to create a new record, if none is found by the filter, and pass the values from [FilterFrm] to that new record in [RecordsFrm]. I hope this makes sense.

Here is my code;

If Me.Filter > "" Then
If IsNull(Me![WrkDate]) And IsNull(Me![Shift]) Then
If msgbox("'The record was not found. Would you like to create it?" & Chr(13) & Chr(10) & _
"Press 'OK' to create the record." & Chr(13) & Chr(10) & _
"Press 'No' to browse records.", _
vbYesNo, "A Required field is Null") = vbYes Then
DoCmd.GoToRecord , , acNewRec
Me![WrkDate].Value = Forms!FilterFrm!DBDate
Me![Shift].Value = Forms!FilterFrm!DBShift
Else
Me.FilterOn = False
End If
End If
End If

I am getting an error(Error 2448) on the two lines;
Me![WrkDate].Value = Forms!FilterFrm!DBDate
Me![Shift].Value = Forms!FilterFrm!DBShift

While debugging I can see that the values from [FilterFrm] are being passed to the code, but everything I have tried has not fixed the problem.

Thanks in advance for any help.
 
The runtime error is '2448-
You can't assign a value to this object'

Is the query editable that the form is based on? Is the form editable?
 
Thanks MajP.
Yes to both. When the MsgBox is displayed and I click "No" I can add or edit a record at that point.

One thing I did not specify is that the code is located in the "On Open" event in [RecordFrm]. The code located in the "On Click" event for the button in [FilterFrm] is;

DoCmd.OpenForm "RecordFrm", acNormal, "", "[wrkdate]=[Forms]![filterfrm]![dbdate] And [shift]=[Forms]![filterfrm]![dbshift]", acEdit, acNormal

DoCmd.Close acForm, "filterfrm"


Could it be a timing issue? What I mean is, is it possible that the form is not actually open, or a new record has not been created prior to the code attempting to assign the values to the two fields?
 
Use the Load event instead of the Open when you play with controls.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
This is a guess, but try switching from on open to on load.
Here is why.
On Open Event

The Open Event occurs when a form is opened, but before the first record is displayed. Therefore, attach code here that you wish to run as soon as the form is opened. The Open event will not occur when you activate (move to a form) a form that's already open, i.e. if you open a second form from the first form, then close the second form, the first form’s On Open Event will not occur as the first form has not been closed and opened, it has just been hidden behind the second form.

If the Form is based on a Query, the Query is run prior to the On Open Event.

On Load Event

Whereas the on Open Event occurs when the form is opened and before the first record is displayed, the On Load Event occurs when the first record is displayed.
 
PHV beat me, but at least we are thinking the same.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top