Sign in to follow this  
Followers 0
9LUCAS

How to use variables?

3 posts in this topic

Hi.

I'm using a function to add information to an Access database. I want to add information from a variable that I have declared previously.

When I open the file access. In the modified fields just appears "$campo", rather than the content of the variable ("campotest").

The function is:

$FULL_MDB_FILE_NAME = @ScriptDir & "\MyDatabase.accdb"
$SQL_CODE = "select * from Table_1"
$CONN = ObjCreate("ADODB.Connection")
$CONN.Open('Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=' & $FULL_MDB_FILE_NAME & ';')
$RecordSet = ObjCreate("ADODB.Recordset")
$CONN.Execute("INSERT into Table_1 (Name, Campo1) values ('$campo', '45326')")
$CONN.Close

I declared the variables as follows:

Global $campo = "campotest"

I am declaring the variables correctly? Is there any error in function?
Thanks in advance.

PS: sorry for my English.

Share this post


Link to post
Share on other sites



This line 

$CONN.Execute("INSERT into Table_1 (Name, Campo1) values ('$campo', '45326')")

should be

$CONN.Execute("INSERT into Table_1 (Name, Campo1) values ('" & $campo & "', '45326')")

 


"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites
2 minutes ago, Bowmore said:

This line 

$CONN.Execute("INSERT into Table_1 (Name, Campo1) values ('$campo', '45326')")

should be

$CONN.Execute("INSERT into Table_1 (Name, Campo1) values ('" & $campo & "', '45326')")

 

Thanks. Solved!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0