PC Review


Reply
Thread Tools Rate Thread

Button on Form Appends Current Record to Another Table

 
 
headly
Guest
Posts: n/a
 
      18th Mar 2009
I figure I'm close with this code, but it generates a syntax error on the
Docmd.RunSQL statement, probably related to my variable assignment above. TIA
for any assistance
Private Sub btnAppend_Click()
'Pass the current record to another table
Dim varID As Variant
varID = Me.ID
Dim mySQL As String
mySQL = "INSERT INTO tblTAs ( FirstName, LastName )" & " SELECT
tblPersonnel.FirstName, tblPersonnel.LastName" & " FROM tblPersonnel WHERE
(((tblpersonnel.id=" & varID & "));"
DoCmd.RunSQL mySQL
End Sub
 
Reply With Quote
 
 
 
 
tina
Guest
Posts: n/a
 
      18th Mar 2009
well, if you posted your code "as is" from the VBA module, then i'd say the
code is written on several lines, but without line breaks. try the
following, as

mySQL = "INSERT INTO tblTAs ( FirstName, LastName )" _
& " SELECT tblPersonnel.FirstName, tblPersonnel.LastName" _
& " FROM tblPersonnel WHERE (((tblpersonnel.id=" & varID & "));"

note the line break character (underscore) at the end of each line. now,
having said that, i have to wonder why you're storing the employee name in
more than one table in the first place. that violates normalization rules,
and is a bad idea unless you have a compelling business or technical reason
for doing so. well, even then it's a bad idea, which is why you shouldn't do
it unless the reason is compelling.

hth


"headly" <(E-Mail Removed)> wrote in message
news:9A63F572-6D49-4CD0-AFCB-(E-Mail Removed)...
> I figure I'm close with this code, but it generates a syntax error on the
> Docmd.RunSQL statement, probably related to my variable assignment above.

TIA
> for any assistance
> Private Sub btnAppend_Click()
> 'Pass the current record to another table
> Dim varID As Variant
> varID = Me.ID
> Dim mySQL As String
> mySQL = "INSERT INTO tblTAs ( FirstName, LastName )" & " SELECT
> tblPersonnel.FirstName, tblPersonnel.LastName" & " FROM tblPersonnel

WHERE
> (((tblpersonnel.id=" & varID & "));"
> DoCmd.RunSQL mySQL
> End Sub



 
Reply With Quote
 
headly
Guest
Posts: n/a
 
      18th Mar 2009
Thanks for trying tina, but not even close; The command is on one line and
the forum is forcing the text to wrap.

"tina" wrote:

> well, if you posted your code "as is" from the VBA module, then i'd say the
> code is written on several lines, but without line breaks. try the
> following, as
>
> mySQL = "INSERT INTO tblTAs ( FirstName, LastName )" _
> & " SELECT tblPersonnel.FirstName, tblPersonnel.LastName" _
> & " FROM tblPersonnel WHERE (((tblpersonnel.id=" & varID & "));"
>
> note the line break character (underscore) at the end of each line. now,
> having said that, i have to wonder why you're storing the employee name in
> more than one table in the first place. that violates normalization rules,
> and is a bad idea unless you have a compelling business or technical reason
> for doing so. well, even then it's a bad idea, which is why you shouldn't do
> it unless the reason is compelling.
>
> hth
>
>
> "headly" <(E-Mail Removed)> wrote in message
> news:9A63F572-6D49-4CD0-AFCB-(E-Mail Removed)...
> > I figure I'm close with this code, but it generates a syntax error on the
> > Docmd.RunSQL statement, probably related to my variable assignment above.

> TIA
> > for any assistance
> > Private Sub btnAppend_Click()
> > 'Pass the current record to another table
> > Dim varID As Variant
> > varID = Me.ID
> > Dim mySQL As String
> > mySQL = "INSERT INTO tblTAs ( FirstName, LastName )" & " SELECT
> > tblPersonnel.FirstName, tblPersonnel.LastName" & " FROM tblPersonnel

> WHERE
> > (((tblpersonnel.id=" & varID & "));"
> > DoCmd.RunSQL mySQL
> > End Sub

>
>
>

 
Reply With Quote
 
John Spencer
Guest
Posts: n/a
 
      18th Mar 2009
Unbalanced parentheses.

mySQL = "INSERT INTO tblTAs ( FirstName, LastName )" & " SELECT
tblPersonnel.FirstName, tblPersonnel.LastName" & " FROM tblPersonnel
WHERE tblpersonnel.id=" & varID

Your where clause had three "(" and two "))". Since none of them were
really needed, I deleted all of them in the where clause.

Hope this helps

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================


headly wrote:
> I figure I'm close with this code, but it generates a syntax error on the
> Docmd.RunSQL statement, probably related to my variable assignment above. TIA
> for any assistance
> Private Sub btnAppend_Click()
> 'Pass the current record to another table
> Dim varID As Variant
> varID = Me.ID
> Dim mySQL As String
> mySQL = "INSERT INTO tblTAs ( FirstName, LastName )" & " SELECT
> tblPersonnel.FirstName, tblPersonnel.LastName" & " FROM tblPersonnel WHERE
> (((tblpersonnel.id=" & varID & "));"
> DoCmd.RunSQL mySQL
> End Sub

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use Form button to move current record to another table JMageeirbc@gmail.com Microsoft Access 4 14th Dec 2007 04:15 PM
Print just the current record via a button on a form =?Utf-8?B?QnJpYW4gSGFsbA==?= Microsoft Access Getting Started 2 31st May 2007 01:12 PM
checking a checkbox appends/updates a record in another table Chris Ryner Microsoft Access Forms 1 20th Apr 2006 09:47 AM
Need to add a button to a form to save the current record in RTF =?Utf-8?B?Q2hhcmxlcw==?= Microsoft Access VBA Modules 2 14th Apr 2005 06:53 AM
Form Button to Save Current Record to RTF =?Utf-8?B?Q2hhcmxlcw==?= Microsoft Access Form Coding 0 8th Apr 2005 10:01 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:42 PM.