Problem Updating Table

CasperS

New member
Local time
Today, 18:07
Joined
May 13, 2002
Messages
8
I could sure use some help! This code will write new records to the table, but when it encounters a record already in the file, the .nomatch statement has a "true" value so that when the .Update statement is run an error is displayed telling me that a duplicate key (SHIPTO and PARTNO) is not allowed. Here's the problem code:

UpdateNewDock:

Rem sSQL2 = "[SHIPTO]='SV_Shipto$' and [PARTNO]='SV_Partno$'"
Rem sSQL2 = "SHIPTO = 'SV_Shipto$' AND PARTNO = 'SV_Partno$'"
Rem SQL2 = "SHIPTO = " & SV_Shipto$ & " AND PARTNO = " & SV_PartNo$
Rem The above stmt adds 1 record to table, then give an error Data Type Mismatch in Criteria Expression
Rem If I let it continue, I see that it correctly yields a "false" from the nomatch statement.

sSQL2 = "SHIPTO='SV_Shipto$' AND PARTNO='SV_PartNo$'"
rstNewDock.FindFirst sSQL2
If rstNewDock.NoMatch Then
With rstNewDock
.AddNew
!SHIPTO = SV_Shipto$
!PARTNO = SV_PartNo$
!MHC = SV_MHC
!DockCode = SV_DockCode
!PCI1 = SV_PCI1
!PCI2 = SV_PCI2
!PCI3 = SV_PCI3
!PCI4 = SV_PCI4
!PCI5 = SV_PCI5
.Update
.Bookmark = rstNewDock.LastModified
End With
Else
With rstNewDock
.Edit
!MHC = SV_MHC
!DockCode = SV_DockCode
!PCI1 = SV_PCI1
!PCI2 = SV_PCI2
!PCI3 = SV_PCI3
!PCI4 = SV_PCI4
!PCI5 = SV_PCI5
.Update
End With
End If
 
I didn't get much interest in my problem, but since I found the solution, I thought I'd post it for someone else who may be looking for a solution to a similar problem. The sSQL2= statement works if it looks like this:

sSQL2 = "SHIPTO = " & Chr$(34) & SV_Shipto & Chr$(34) & " AND PARTNO = " & Chr$(34) & SV_PartNo & Chr$(34)
 

Users who are viewing this thread

Back
Top Bottom