Re: Insert Into SQL
- From: "Allen Browne" <AllenBrowne@xxxxxxxxxxxxxx>
- Date: Mon, 22 Oct 2007 09:48:36 +0800
If you really want a book on SQL, "SQL for Mere Mortals" would be good (John Viescas and Michael Hernandez)
Hopefully you are aware that you can build any query in the graphical query design window, and then switch to SQL View (Query menu, in query design.) What I do is build the query there using any old criteria, and then copy it to the code window. You then have to concatenate the query into the string, adding the " quotes for Text fields or the # delimiter for Date fields.
Here's some info about how to add the quotes:
http://allenbrowne.com/casu-17.html
And here's the form I use to copy the SQL statement into code:
http://allenbrowne.com/ser-71.html
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Chuck" <libbeyc@xxxxxxxxxxxxxx> wrote in message
news:bbkmh3d9fpmthe7mg46nkm66s871dv4omv@xxxxxxxxxx
On Sun, 21 Oct 2007 11:15:39 +0800, "Allen Browne" <AllenBrowne@xxxxxxxxxxxxxx>
wrote:
You need to concatenate the value from Text1 on Form1 into the string.
This kind of thing:
Function InsertEm()
Dim db As DAO.Database
Dim strSql As String
If Not IsNull(Forms!Form1!Text1) Then
strSql = "INSERT INTO tblWT1 ( Mfg, Series, Model, Config, Options )
" & _
"SELECT tblMain.Mfg, tblMain.Series, tblMain.Model, " & _
"tblMain.Config, tblMain.Options FROM tblMain " & _
"WHERE tblMain.Mfg = """ & Forms!Form1!Text1 & """;"
Set db = DBEngine(0)(0)
db.Execute strSql, dbFailOnError
MsgBox db.RecordsAffected & " record(s) inserted."
End If
set db = Nothing
End Function
If Mfg is a Number field (not a Text field), drop the extra quotes, i.e.:
"WHERE tblMain.Mfg = " & Forms!Form1!Text1 & ";"
No luck.
Been looking in Amazon.com for a book on SQL. Most seem to be SQL Server.
Don't think those are what I need. I'm working on a simple little stand alone
A97 database on my home computer. If I ever get to a city large enough to have
a Barns and Noble, then I can 'peek' to see if anything looks like something I
could use. Any book suggestions you may have would be greatly appreciated.
Chuck
--
.
- Follow-Ups:
- Re: Insert Into SQL
- From: Chuck
- Re: Insert Into SQL
- From: Chuck
- Re: Insert Into SQL
- From: Chuck
- Re: Insert Into SQL
- References:
- Insert Into SQL
- From: Chuck
- Re: Insert Into SQL
- From: Allen Browne
- Re: Insert Into SQL
- From: Chuck
- Re: Insert Into SQL
- From: Allen Browne
- Insert Into SQL
- Prev by Date: Rename a folder
- Next by Date: Re: Rename a folder
- Previous by thread: Re: Insert Into SQL
- Next by thread: Re: Insert Into SQL
- Index(es):
Relevant Pages
|