Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding a variable to a Database

Status
Not open for further replies.

raghitchen

Technical User
Nov 17, 2003
4
GB
Hi this is probally a pretty simple one.

All I need to do is write a series of variables I have obtained via VBA code (behind an access form button) referencing some 3rd party data. I now want to add the data in the variables into an access database that I have created in the same project. What is the syntax to do this?

The table is called Music which contains fields Title, Artist, Type and I have the correct data for each of these fields in memory.

Any advice would be appreciated.

 
Can you use a SQL code in VBA

Dim cnn As ADODB.Connection
Set cnn = CurrentProject.Connection

strSQL = "INSERT INTO Music"
strSQL = strSQL & vbCrLf & "VALUES ('" & Title & "','"
strSQL = strSQL & Artist & "','" & Type & "')"

cnn.Execute strSQL

MUSIC, TITLE, and ARTIST are variables known within the VBA
Give that a go and let me know if it works.

dyarwood
 
No problem. I just had to do a similar thing in my DB just before your post.

dyarwood
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top