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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Custom Insert Statement

Status
Not open for further replies.

kosmokramer

Programmer
Sep 8, 2002
73
0
0
US
I am working on some forms, and when I try the "Add New Record" method that pops up as one of the options in the actions for a new command button, it does not work for my form. Some fields it does not even let me enter information into at all. So, what I am going to do is create a whole new form for inserting into the database, leave the fields unbound and just use an Insert to grab the information off the form and insert it.

So, how do you write an Insert statement for the form? I know how to do one in Visual Basic 6.0, but since this version of VB is in Access (and is with the database already), you wouldn't have to write a connectionstring and all that stuff would you? Also, would the insert statement be the same? Something like this:
Code:
Insert into myTable (firstRow, secondRow, thirdRow) Values (firstField.text, secondField.text, thirdField.text)
 
Here is one approach ... htwh,

Dim ThisDB as DAO.Database
Dim lcSQL as String

Set ThisDB = CurrentDB

lcSQL = "Insert into MyTable "
lcSQL = lcSQL & "(Field1, Field2,..."
lcSQL = lcSQL & "VALUES (...."

Thisdb.Execute lcSQL, dbFailOnError

Steve Medvid
"IT Consultant & Web Master"

Chester County, PA Residents
Please Show Your Support...
 
Something like this:
DoCmd.RunSQL "Insert into myTable (firstRow, secondRow, thirdRow) Values ('" & firstField.text & "','" & secondField.text & "','" & thirdField.text & "')"
Don't use single quotes for numeric fields.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top