N
Nacho
I have the following code.
When ever i try to open a recorset with a SQL statement using LEFT JOIN, i
get the 3061 error, "too few parameters. Expected 1"
the code:
----------------------------------------------
Function BaseDST()
Dim DBNew As Database
Dim DBVar As Database
Dim Recset As Recordset
Dim Recset2 As Recordset
Dim sSQL As String
Dim i, n As Integer
Dim vflag, vflag2, vflag3 As Boolean
Set DBNew = CurrentDb
'Set DBVar = CurrentDb
sSQL = "SELECT [Base DST].[Order Number], [Base DST].[RFS] as RFS, [Base DST
versión anterior].[RFS date] AS RFSant,"
sSQL = sSQL & " [Base DST].[Plant Month] As PM, [Base DST versión
anterior].[Plant Month] AS PMant, [Base DST].[Tons] AS tons,"
sSQL = sSQL & " [Base DST versión anterior].[Tons] as tonsant"
sSQL = sSQL & " FROM [Base DST] LEFT JOIN [Base DST versión anterior] ON
[Base DST].[Order Number] = [Base DST versión anterior].[Order Number]"
sSQL = sSQL & " WHERE (([Base DST versión anterior].[Mill] <> Null) AND
([Base DST].[Source Type] = 'PREVISION'))"
'MsgBox sSQL
Set Recset = DBNew.OpenRecordset(sSQL)
Set Recset2 = DBVar.OpenRecordset("Variacion de previsiones")
Recset.MoveFirst
Do While Not Recset.EOF
If Recset.Fields("RFS") <> Recset.Fields("RFSant") Then vflag = True
If Recset.Fields("PM") <> Recset.Fields("PMant") Then vflag2 = True
If Recset.Fields("tons") <> Recset.Fields("tonsant") Then vflag3 = True
If vflag = True Or vflag2 = True Or vflag3 = True Then
Recset2.AddNew
Recset2.Fields("Order Number") = Recset.Fields("Order Number")
Recset2.Fields("RFS") = vflag
Recset2.Fields("Plant Month") = vflag2
Recset2.Fields("Tons") = vflag3
Recset2.Update
End If
vflag = False
vflag2 = False
vflag3 = False
Recset.MoveNext
Loop
Set DBNew = Nothing
Set DBVar = Nothing
End Function
When ever i try to open a recorset with a SQL statement using LEFT JOIN, i
get the 3061 error, "too few parameters. Expected 1"
the code:
----------------------------------------------
Function BaseDST()
Dim DBNew As Database
Dim DBVar As Database
Dim Recset As Recordset
Dim Recset2 As Recordset
Dim sSQL As String
Dim i, n As Integer
Dim vflag, vflag2, vflag3 As Boolean
Set DBNew = CurrentDb
'Set DBVar = CurrentDb
sSQL = "SELECT [Base DST].[Order Number], [Base DST].[RFS] as RFS, [Base DST
versión anterior].[RFS date] AS RFSant,"
sSQL = sSQL & " [Base DST].[Plant Month] As PM, [Base DST versión
anterior].[Plant Month] AS PMant, [Base DST].[Tons] AS tons,"
sSQL = sSQL & " [Base DST versión anterior].[Tons] as tonsant"
sSQL = sSQL & " FROM [Base DST] LEFT JOIN [Base DST versión anterior] ON
[Base DST].[Order Number] = [Base DST versión anterior].[Order Number]"
sSQL = sSQL & " WHERE (([Base DST versión anterior].[Mill] <> Null) AND
([Base DST].[Source Type] = 'PREVISION'))"
'MsgBox sSQL
Set Recset = DBNew.OpenRecordset(sSQL)
Set Recset2 = DBVar.OpenRecordset("Variacion de previsiones")
Recset.MoveFirst
Do While Not Recset.EOF
If Recset.Fields("RFS") <> Recset.Fields("RFSant") Then vflag = True
If Recset.Fields("PM") <> Recset.Fields("PMant") Then vflag2 = True
If Recset.Fields("tons") <> Recset.Fields("tonsant") Then vflag3 = True
If vflag = True Or vflag2 = True Or vflag3 = True Then
Recset2.AddNew
Recset2.Fields("Order Number") = Recset.Fields("Order Number")
Recset2.Fields("RFS") = vflag
Recset2.Fields("Plant Month") = vflag2
Recset2.Fields("Tons") = vflag3
Recset2.Update
End If
vflag = False
vflag2 = False
vflag3 = False
Recset.MoveNext
Loop
Set DBNew = Nothing
Set DBVar = Nothing
End Function