Is there a better why to quickly add a new record ?

Access 2010 vba
sql server linked  tables

Trying to add a new record...taking a very long time to with code

Set R = CurrentDb.OpenRecordset("dbo_t_nsc_trackcode_trans_time_entry", dbOpenDynaset, dbSeeChanges) ''' CLOCKED HERE FOR  15 SECS  03/06/2018
           '          Set R = CurrentDb.OpenRecordset("SELECT * FROM [dbo_t_nsc_trackcode_trans_time_entry]", dbOpenDynaset, dbSeeChanges)
                    R![NSC_ID_Ref] = Me.NSC_Id
                    R![InProgress_or_Closed_at] = Now()
             Set R = Nothing

Open in new window

Is there a better why to quickly add a new record ?

Thanks fordraiders
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dale FyeOwner, Developing Solutions LLCCommented:
you could execute an append query:

strSQL = "INSERT INTO [dbo_t_NSC_trackcode_trans_time_entry] (NSC_ID_Ref, InProgress_or_Closed_at]) " +
       & "Values( " & me.NSC_ID & ", #" & Now() & "#)"
currentdb.execute strsql, dbSeeChanges

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fabrice LambertFabrice LambertCommented:

just execute a query:
dim SQL as string
SQL = "INSERT INTO [dbo_t_nsc_trackcode_trans_time_entry](NSC_ID_Ref, InProgress_or_Closed_at)" & vbcrlf
SQL= SQL & "VALUES ("  & Me.NSC_Id & ", GETDATE());"

dim db as dao.database
set db = currentdb
db.execute sql, dbFailOnError

Open in new window

PS: If the InProgress_or_Closed_at column always represent the date and time when the record was added, a trigger or  a default value should handle this in your database design, this way, you won't have to worry about it in your queries.
FordraidersAuthor Commented:
Thanks all,
I forgot to add one more field that may be a problem ?  getting a value from main form

'R![opened_at] = Forms!nsc_dataentry.txtReOpened

I cant get the syntax to take
errors below

Dim ttt As date
ttt = Forms!nsc_dataentry.txtReOpened

' trying this 

             If txtCid_Form = Me.NSC_Id Then
                 If Forms!nsc_dataentry.txtReOpened.Value <> "" Then
                    strSQL_sql = "INSERT INTO [dbo_t_nsc_trackcode_trans_time_entry](NSC_ID_Ref, [opened_at], InProgress_or_Closed_at)" & vbCrLf
                    strSQL_sql = strSQL_sql & "VALUES (" & Me.NSC_Id & "," & ttt & " , now());"

Open in new window

Thanks !
 variable value
and error messageerror message
Gustav BrockCIOCommented:
You don't need to open the full table. Try this:

Set R = CurrentDb.OpenRecordset("SELECT TOP 1 * FROM [dbo_t_nsc_trackcode_trans_time_entry]", dbOpenDynaset, dbSeeChanges)

Open in new window


Set R = CurrentDb.OpenRecordset("SELECT * FROM [dbo_t_nsc_trackcode_trans_time_entry] WHERE False", dbOpenDynaset, dbSeeChanges)

Open in new window

or, if that fails:

Set R = CurrentDb.OpenRecordset("SELECT * FROM [dbo_t_nsc_trackcode_trans_time_entry] WHERE (1=0)", dbOpenDynaset, dbSeeChanges)

Open in new window

FordraidersAuthor Commented:
Thanks all,
The insert statement was 15 secs...faster..

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.