Sabtu, 07 Oktober 2017

RE: RE: [MS_AccessPros] Syntax error in INSERT INTO statement.

 

Hi Duane

Yes, I think you are quite right – you can use a UDF for the default value of a form control bound to a field, but not for the field itself.

Sunday morning and not enough coffee – thanks for the face slap J

Cheers,
Graham

 

From: MS_Access_Professionals@yahoogroups.com [mailto:MS_Access_Professionals@yahoogroups.com]
Sent: Sunday, 8 October 2017 11:49
To: MS_Access_Professionals@yahoogroups.com
Subject: Re: RE: [MS_AccessPros] Syntax error in INSERT INTO statement.

 

 

Graham,

 

I'm not sure a user-defined function can be used as a default field value in a table. I tried using my favorite fOSUserName() and Access didn't like it.

 

 

Duane

 


From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of 'Graham Mandeno' graham@mandeno.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Saturday, October 7, 2017 5:28 PM
To: MS_Access_Professionals@yahoogroups.com
Subject: RE: RE: [MS_AccessPros] Syntax error in INSERT INTO statement.

 

 

Hi Art

I totally agree with Duane about not using "Date" as a field name.  You should change it to "LogDate" or some such name that is not a reserved word.

However, I tried the string in your latest message (actually copied and pasted it from your message) and I get a different result from what you report:

INSERT INTO Logs (UserId, Date, Operation) Values ('admin',Now(),'Successfully logged in')

Note that "Now()" (not the current date and time) is embedded in the string.

Duane's idea of setting the default value of LogDate to "=Now()" is also a good one and, extending on that, you could also set the default value of UserId to "=GetThisUser()", where GetThisUser is a public function returning the user name.

Best wishes,
Graham

 

From: MS_Access_Professionals@yahoogroups.com [mailto:MS_Access_Professionals@yahoogroups.com]
Sent: Sunday, 8 October 2017 07:46
To: MS_Access_Professionals@yahoogroups.com
Subject: Re: RE: [MS_AccessPros] Syntax error in INSERT INTO statement.

 

 

Art,

 

Graham suggested you need "#" to delimit date and time values. Did you try these?

 

I would probably set the default value of [Date] Now() and then use:

 

Public Sub LoggingActivity(Activity As String)

  Dim strSQLInsert as String

  strSQLInsert = "INSERT INTO Logs (UserId, Operation) Values ('" & gstrThisUser & "','" & Activity & "')"

  CurrentDb.Execute strSQLInsert, dbFailOnError

End Sub

 

Also, Date shouldn't be used except to call the Date() function http://allenbrowne.com/AppIssueBadWord.html#D

allenbrowne.com

Problem names and reserved words in Access. This list, from the Database Issue Checker Utility, is a quick reference of words that may cause problems as field or ...

 

 

Regards,

Duane Hookom

 

 


From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of Art Lorenzini dbalorenzini@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Saturday, October 7, 2017 1:03 PM
To: 'Graham Mandeno' graham@mandeno.com [MS_Access_Professionals]
Subject: Re: RE: [MS_AccessPros] Syntax error in INSERT INTO statement.

 

 

Updated the function to"

 

Public Sub LoggingActivity(Activity As String)

  CurrentDb.Execute "INSERT INTO Logs (UserId, Date, Operation) Values ('" & gstrThisUser & "',Now(),'" & Activity & "')"
 
 
 
 End Sub

 

 

Still recieveing the Insert Into Error;

 

I checked for the contents of Currentdb.Execute and it is this.

 

INSERT INTO Logs (UserId, Date, Operation) Values ('admin','10/7/2017 1:01:06 PM','Successfully logged in')

 

Now() is returning the correct date/time but is formatted incorrectly...???


With Warm Regards,

 

Arthur D. Lorenzini

IT System Manager

Cheyenne River Housing Authority

Wk.(605)964-4265  Ext. 130

Fax (605)964-1070

 

"Valar Dohaeris"



 

 

On ‎Friday‎, ‎October‎ ‎6‎, ‎2017‎ ‎04‎:‎50‎:‎42‎ ‎PM, 'Graham Mandeno' graham@mandeno.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

 

 

 

Hi Art

You need to delimit SQL dates with hash/pound signs (#) not quotes, and they need to be formatted in a particular way.  However, in your case you wish to insert the current date and time, and SQL understands the Now() function, so you don't need to substitute its value and delimit it.

Try this:

strSQL = "INSERT INTO Logs (UserId, Date, Operation) Values ('" & gstrThisUser & "',Now(),'" & Activity & "')"

Best wishes,
Graham

 

From: MS_Access_Professionals@yahoogroups.com [mailto:MS_Access_Professionals@yahoogroups.com]
Sent: Saturday, 7 October 2017 09:24
To: MS_Access_Professionals@yahoogroups.com
Subject: [MS_AccessPros] Syntax error in INSERT INTO statement.

 

 

I am receiving the following error when I run the function below:

Syntax error in INSERT INTO statement.

 

This is the call to the function:

 modUtilities.LoggingActivity "Successfully logged in"

 

The function defined:

 

 Public Sub LoggingActivity(Activity As String)
 Dim strSQL As String
 strSQL = "INSERT INTO Logs (UserId, Date, Operation) Values ('" & gstrThisUser & "','" & Now() & "','" & Activity & "')"
  CurrentDb.Execute "INSERT INTO Logs (UserId, Date, Operation) Values ('" & gstrThisEmpName & "','" & Now() & "','" & Activity & "')"
  End Sub


  Contents of strSQL:

INSERT INTO Logs (UserId, Date, Operation) Values ('admin','10/6/2017 3:22:31 PM','Successfully logged in')

 

And for the life of me that looks like it should work....

 

Any ideas?

 

Thank you,

Art Lorenzini

SD

 


  

 

 

__._,_.___

Posted by: "Graham Mandeno" <graham@mandeno.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (7)

Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.


.

__,_._,___

Tidak ada komentar:

Posting Komentar