Automatically create record if it doesnt exist

Gruung

Registered User.
Local time
Today, 04:23
Joined
Nov 25, 2003
Messages
35
I have a form with a command button to open up a subform which is directly related to the studentID. Is there a way that if that ID doesnt exist it will automatically create a record, filling in the student ID and leaving the rest blank?
 
If you don't want to add any data pertinent to that student what would be the point?
 
write this code
in the subform
me.recordset.findfist "Studentn = " & [forms][formname][fieldname].value
if nomatch then
me.recordset.addnew
end if

I hope this helps u.

If I see u again I will kill u
with blood,
Sahroon
 
me.recordset.findfist "Studentn = " & [forms][formname][fieldname].value
if nomatch then
me.recordset.addnew
end if

I understand that last bit of code but what is the first line for? I am adding this code to a command button that opens the subform and compares the studentID's, is there any point in adding the first line then?

thanks
 
There is no point to adding an empty row to a table and then updating it. Add the row when you have data.
 
Sorry i obviouly wasnt clear, I want it to automatically fill in the student ID, as the user will not be able to remember that. So it creates the record and adds studentID but leaves the rest blank.
 
If the user can't remember the ID, how would he find the record to update it?
 
Right there is a command button that opens a subform that is directly related to the student ID open then. So if ID 1 is open ID 1 will open in the subform. So they will find the record in the main form. What I want to happen is that if there is no match for that perticular student ID i wnat a record created with the student ID filled in and they can fill out the rest of the information.
 
You are making this harder than it needs to be. When you open the form using the OpenForm method, use the where argument. If there are no matching records, the form will open up empty. The user can then add data.

All you need is a single line of code in the popup form's BeforeInsert event:

Me.StudentID = Forms!YourMainForm!StudentID

If the user chooses not to enter data at this time, no record is created. As soon as he types a single character in any field, the record is "dirtied" and so Access will save the record automatically when the form is closed.
 

Users who are viewing this thread

Back
Top Bottom