syntax problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have just created a new person record in frmAddPerson, based on tblPeople
I need to create matching records in tblVersion and tblEval, which are not part of frmAddPerson
I created frmAddVersion which is opened to create the tblVersion record. It's clumsy but works
DoCmd.GoToRecord acDataTable = "tblVersion", acNewRec
gives a type mismatch
What is the correct format
 
Desert Bear said:
I have just created a new person record in frmAddPerson, based on
tblPeople.
I need to create matching records in tblVersion and tblEval, which
are not part of frmAddPerson. I created frmAddVersion which is opened
to create the tblVersion record. It's clumsy but works.
DoCmd.GoToRecord acDataTable = "tblVersion", acNewRec
gives a type mismatch.
What is the correct format?

I'm not sure, because it isn't clear to me what that line is supposed to
do. If you've opened frmAddVersion in normal mode and now want to tell
it to go to a new record, you would write

DoCmd.GoToRecord acDataForm, "frmAddVersion", acNewRec

If you only want to open this form for the purpose of adding a new
record, you could open the form in data entry mode in the first place:

DoCmd.OpenForm "frmAddVersion", DataMode:acFormAdd

And if the form is designed *only* to be opened in "add" mode, you could
set that in the form's properties, just by setting the form's Data Entry
property to Yes. Then you wouldn't even have to specify the data mode
when opening the form.

Be aware, by the way, if you aren't already, that if you already have
all the information you need to create the new records, you don't have
to open forms to do it. You can just add the records directly to the
underlying tables, without opening the forms. You'd only open the forms
if you need the user to provide more information for each record than
you already have.
 
Thanks--your reply contained useful information
I am opening the form just for the purpose of creating a record
Is there a way to do it using DoCmd, as I don't need any data (except the linking peoID) yet
Or do I need to generate an update query
I'm not familiar enough with Access to know how to use some of the commands
 
Desert Bear said:
Thanks--your reply contained useful information.
I am opening the form just for the purpose of creating a record.
Is there a way to do it using DoCmd, as I don't need any data (except
the linking peoID) yet? Or do I need to generate an update query?
I'm not familiar enough with Access to know how to use some of the
commands

If you've got the peoID in a variable, say lngID, you can do it by
building and executing an append query in code. You can execute such a
query using DoCmd.RunSQL, but I prefer to use the DAO Execute method,
like this:

CurrentDb.Execute _
"INSERT INTO tblVersion (peoID) VALUES(" & lngID & ")", _
dbFailOnError

That's assuming that peoID (in tblVersion) is of type Number/Long.

I do have reservations about the practice of creating "empty" records in
tables, which seems to be what you're doing with tblVersion and tblEval.
Normally I see no point in doing this.
 
Thanks. I'll probably try the SQL append.
The 'empty' record is half filled with default values and is needed for a 3rd table to link to, which should be created immediately under normal circumstances.
 
Back
Top