INSERT INTO Not working correctly

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I have a command button that does a "Copy" but more of a INSERT INTO command
on 3 subtables. If I comment out the first 2 INSERT INTO blocks then the 3rd
INSERT INTO command works. If I uncomment out the first 2 INSERT INTO
commands then the 3rd doesn't work. What am I doing wrong? Here's my code.

Private Sub Command63_Click()
'On Error GoTo Err_Handler
'Purpose: Duplicate the main form record and related records in the
subform.
Dim strSql As String 'SQL statement.
Dim strSql1 As String 'SQL Statement 2.
Dim strSqlA As String

Dim lngID As Long 'Primary key value of the new record.

'Save and edits first
If Me.Dirty Then
Me.Dirty = False
End If

'Make sure there is a record to duplicate.
If Me.NewRecord Then
MsgBox "Select the record to duplicate."
Else
'Duplicate the main record: add to form's clone.
With Me.RecordsetClone
.AddNew
!ProjectName = Me.ProjectName
![DEA/SRALeads] = Me.[DEA/SRALeads]
!PhaseComplDateReqPlan = Me.PhaseComplDateReqPlan
!PhaseComplDateDesign = Me.PhaseComplDateDesign
!PhaseComplDateDevelopment = Me.PhaseComplDateDevelopment
!PhaseComplDatePilot = Me.PhaseComplDatePilot
!PhaseComplDateTransition = Me.PhaseComplDateTransition
!ReqPlanStatus = Me.ReqPlanStatus
!DesignStatus = Me.DesignStatus
!DevelopmentStatus = Me.DevelopmentStatus
!PilotStatus = Me.PilotStatus
!TransitionStatus = Me.TransitionStatus
!Other = Me.Other

'etc for other fields.
.Update

'Save the primary key value, to use as the foreign key for the
related records.
.Bookmark = .LastModified
lngID = !WebFarmID

MsgBox "LAST WEEK'S WAR DATA HAS BEEN COPIED"

'Duplicate the related records: append query.
If Me.[frmWebFarmNewAIs].Form.RecordsetClone.RecordCount > 0 Then
strSql = "INSERT INTO [tblWebFarmNewAIs] ( WebFarmID,
ActionItem, Owner) " & _
"SELECT " & lngID & " As NewID, ActionItem, Owner " & _
"FROM [tblWebFarmNewAIs] WHERE WebFarmID = " &
Me.WebFarmID & ";"
DBEngine(0)(0).Execute strSql

If Me.[frmWebFarmOverdueAIs].Form.RecordsetClone.RecordCount > 0
Then
strSql1 = "INSERT INTO [tblWebFarmOverdueAIs] (WebFarmID,
ActionItemOverdue, Owner) " & _
"SELECT " & lngID & " As NewID, ActionItemOverdue, Owner
" & _
"FROM [tblWebFarmOverdueAIs] WHERE WebFarmID = " &
Me.WebFarmID & ";"

DBEngine(0)(0).Execute strSql1

If Me.[frmWebFarmDeliverables].Form.RecordsetClone.RecordCount >
0 Then
strSqlA = "INSERT INTO [tblWebFarmDeliverables] (WebFarmID,
Deliverable, Completed) " & _
"SELECT " & lngID & " As NewID, Deliverable, Completed "
& _
"FROM [tblWebFarmDeliverables] WHERE WebFarmID = " &
Me.WebFarmID & ";"

DBEngine(0)(0).Execute strSqlA
Else
MsgBox "Main record duplicated, but there were no related
records."
End If
End If
End If

'Display the new duplicate.
Me.Bookmark = .LastModified
End With
End If

Exit_Handler:
Exit Sub

Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description, ,
"command63_Click"
Resume Exit_Handler
End Sub

.



Relevant Pages

  • Re: Cannot Browse the Domain in the Network Neighborhood
    ... Explanation of command ... > duplicate SPN's listed where the event log's say they should be. ... > one of the alleged duplicate SPN's is the name of my domain controller. ... >> With respect to the KDC errors are you referring to KDC event id 11's? ...
    (microsoft.public.windows.server.sbs)
  • Re: problem with short date
    ... You say you want to add a "Duplicate record" command but you get an error ... Doug Steele, Microsoft Access MVP ...
    (microsoft.public.access.forms)
  • phantom drive
    ... I have the same problem I believe it was caused by drag to disk I tried the mount vol command but it did not work for me but not sure I did it correctly would like to know if you find a solution ... In windows explorer I see a C: and E: harddrive. ... But E: duplicate of C: is always present on reboot. ...
    (microsoft.public.windowsxp.hardware)
  • Re: controlling cmd.exe via named pipes
    ... I use them to avoid handling named pipes directly by Windows ... 1-I create two different named pipes, say 'cmdIN' and 'cmdOUT'; ... That's the command switch that tells Cmd to run the command on the command line, and then wait for more commands. ... You can duplicate them into Cmd's process because that process doesn't exist yet. ...
    (comp.lang.pascal.delphi.misc)
  • SQL code generates error message
    ... I'm getting an error message when I press my button that states "The changes ... duplicate values in the index, primary key, or relationship. ... Private Sub Command5_Click ... Dim strSql As String ...
    (microsoft.public.access.formscoding)