What is the VBA code to create a new entry in the table, e.g. doCmd..........? (1 Viewer)

rowardHoark

Registered User.
Local time
Today, 08:40
Joined
Jan 14, 2011
Messages
20
DoCmd.GoToRecord , , acNewRec does not seem to work. I want to specify a particular table where that new record is created.
 

DCrake

Remembered
Local time
Today, 07:40
Joined
Jun 8, 2005
Messages
8,632
This will take you to the next new record in the table that is bound to the form your are using.
 

rowardHoark

Registered User.
Local time
Today, 08:40
Joined
Jan 14, 2011
Messages
20
This will take you to the next new record in the table that is bound to the form your are using.

I want to be able to specify a particular table, not just the one bound to the form?

The coding should include the name of a table.
 

DCrake

Remembered
Local time
Today, 07:40
Joined
Jun 8, 2005
Messages
8,632
So Ok lets visualise this

You have a form that is bound to TableA then form contains fields from TableA that are bound in the control source.

You now want to issue a command so that Access goes to a new record in TableB.

So OK does that. What are you going to do then. You can't do anythin with it as the form is boun to TableA not TableB.

More Info please as to your intentions/logic.
 

rowardHoark

Registered User.
Local time
Today, 08:40
Joined
Jan 14, 2011
Messages
20
So Ok lets visualise this

You have a form that is bound to TableA then form contains fields from TableA that are bound in the control source.

You now want to issue a command so that Access goes to a new record in TableB.

So OK does that. What are you going to do then. You can't do anythin with it as the form is boun to TableA not TableB.

More Info please as to your intentions/logic.

I figured out another way to achieve what I want:

strSQL = "INSERT INTO t_add_information "

The table t_add_information starts with an autoNumber. How do I create a new autonumber with this statement, but leave all the other fields in the row empty?
 

vbaInet

AWF VIP
Local time
Today, 07:40
Joined
Jan 22, 2010
Messages
26,374
By simply inserting a new record into that table a new number is automatically generated for you.

Obviously you have to run the code.


DoCmd.RunSQL "INSERT ..."
OR
CurrentDb.Execute "INSERT ..."
 

rowardHoark

Registered User.
Local time
Today, 08:40
Joined
Jan 14, 2011
Messages
20
By simply inserting a new record into that table a new number is automatically generated for you.

Obviously you have to run the code.


DoCmd.RunSQL "INSERT ..."
OR
CurrentDb.Execute "INSERT ..."

The code is executed as an on click event

DoCmd.RunSQL "INSERT INTO t_add_information" prompts a syntax error

strSQL="INSERT INTO t_add_information" prompts no error, but neither is the record created

DoCmd.RunSQL "INSERT INTO t_add_information (Product_name)VALUES(Insulin)" creates a new record, but is not what I am after - I do not want to enter values.
 

vbaInet

AWF VIP
Local time
Today, 07:40
Joined
Jan 22, 2010
Messages
26,374
There's more to that syntax. Create an Append query and look at the syntax there.

DoCmd.RunCommand accmdrecordsgotonew

Creates a new record with a new ID but leaves the other controls blank.
 

rowardHoark

Registered User.
Local time
Today, 08:40
Joined
Jan 14, 2011
Messages
20
There's more to that syntax. Create an Append query and look at the syntax there.

DoCmd.RunCommand accmdrecordsgotonew

Creates a new record with a new ID but leaves the other controls blank.

I have tried to create an append query using design view, however it seems to require that I specify fields. Which fields do I specify? All? Just one? If I do specify a field, I run into various. If no previous records are existent, the append query can't create a new record. If previous records exist, every time and append query is executed, the number of records created grows exponentially 2, 4, 8....

How can I specify DoCmd.RunCommand accmdrecordsgotonew to be executed for a particular table, e.g. DoCmd.t_add_information.RunCommand accmdrecordsgotonew?
 

vbaInet

AWF VIP
Local time
Today, 07:40
Joined
Jan 22, 2010
Messages
26,374
Drop it as a subform, set focus to the subform and run the records go to new.
 

shiznaw

Registered User.
Local time
Yesterday, 23:40
Joined
Feb 3, 2016
Messages
18
The Command: DoCmd.GoToRecord , , acNewRec
Doesn't just take you to a new record, it actually records / adds a new record to the Table to which your control is bound.

John Allen Shaw
 

Users who are viewing this thread

Top Bottom