Using parameters for New Record on Open

kelsita_05

Registered User.
Local time
Yesterday, 21:02
Joined
Aug 23, 2005
Messages
52
I found some posts that might help with my problem, but unfortunately the code is way over my head.
I have a subform (Feedback) that opens from it's parent. It draws two fields (job number and name) from the parent form, and that is working just fine. I set the On Open to create a new record, which is what it needs to do 90% of the time.
However, if a record has already been created for the job number and name on the parent form, I don't want it to create a new record. I want it to show the record that has already been made.
How can I get it to check the table before it creates a new record? The job number and name are the primary keys in the table where the new records are created. I have it set up to check for duplicates (i.e. save) after several fields are completed, but I want it to check ahead of time.
This is the code I'm using (for both creating the new record and checking for duplicates):

Private Sub Text1_LostFocus()
On Error GoTo Err_Text1_LostFocus

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Exit_Text1_LostFocus:
Exit Sub

Err_Text1_LostFocus:
If Err.Number = 3022 Then ' Generate a "duplicate value" error.
MsgBox "This contractor has already been given feedback for this job. Please scroll up or use the record navigation arrows at the bottom of the screen to find that record."
Else
MsgBox Err.Description
End If
Resume Exit_Text1_LostFocus

End Sub

Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open


DoCmd.GoToRecord , , acNewRec

Exit_Form_Open:
Exit Sub

Err_Form_Open:
MsgBox Err.Description
Resume Exit_Form_Open

End Sub


Please show me how to put whatever I need to into the code, as my visual basic is less than adequate.

Thanks so much!
 
You are taking the wrong approach.

You're subform should be linked to the parent form vis the subform's Link Child Fields and Link Mater Fields properties. These link properties are the fields in to parent and child which are related, usually primary keys.

A change in the parent will cause the subform to tumble to the correct child(ren) or to a null record for which new data may be input.
 

Users who are viewing this thread

Back
Top Bottom