Insert into .......

ECEK

Registered User.
Local time
Today, 23:47
Joined
Dec 19, 2012
Messages
717
I have a splash screen (unbound form) that determins the name of the folder that the application is in (this is used to establish the user).

On Open
Code:
Me.TXTPATH = Application.CurrentProject.Path

There is a text field on the Splash form called TXTPATHUSER with the following to clean it up:
Code:
=Mid([TXTPATH],InStrRev([TXTPATH],"\")+1)

I have a table called tblSettings with a field called UserName.

I want to (OnTimer of the Splash screen) insert Me.TXTPATHUSER into the tblSettings, UserName field.

I've tried this:
Code:
DoCmd.RunSQL ("INSERT INTO tblSettings ( UserName )VALUES (Me.TXTPATHUSER);")
But my error is asking me for Me.TXTPATHUSER which IS on the unbound form. Am I referencing the text box correctly?

I can get text to insert i.e.
Code:
DoCmd.RunSQL ("INSERT INTO tblSettings ( UserName )VALUES ('Any Text You Like');")


Your help is always appreciated.
 
Found the answer after writing but thought this might be useful for others:
The referencing of the text field was indeed wrong. I needed to remove the "Me."

Solution
Code:
DoCmd.RunSQL ("INSERT INTO tblSettings ( UserName )VALUES (TXTPATHUSER);")
 
I'm surprised that works. You would normally need to concatenate the value as a string into the SQL statement;

Code:
DoCmd.RunSQL ("INSERT INTO tblSettings ( UserName )VALUES ('" & Me.TXTPATHUSER  & "');")
 

Users who are viewing this thread

Back
Top Bottom