A
Amduke
Hello,
I'm a novice in VBA but I try to get a living out of it.
I want to append records in a table. But while doing it, an error came up.
There was a record with a null value.
To avoid problems I thought, maybe I can create a variable to check if the
value is realy null.
Now I'm facing an error telling me: "Object required" ;-(
Find here some code I've written. Can somebody help me out?
Dim V_mabc As String
Dim V_comp As String
Dim V_tcost As Single
Dim V_share As Single
Dim V_cuco As String
Dim V_perc As Single
Dim V_cumprc As Single
'Position on top of the table
rstTable.MoveFirst
'Run thru the table from begin to end
While Not rstTable.EOF
'For Each Field In rstTable.Fields
'First we fill up the variables
F_mabc = rstResult.Fields(0).Name
F_comp = rstResult.Fields(1).Name
F_tcost = rstResult.Fields(2).Name
F_share = rstResult.Fields(3).Name
F_cuco = rstResult.Fields(4).Name
F_perc = rstResult.Fields(5).Name
F_cumprc = rstResult.Fields(6).Name
'Values in variables
V_mabc = rstTable.Fields(0).Value
V_cumprc = "0"
'Check for null values
If rstTable.Fields(1).Value Is Null Then
V_comp = Space(0)
Else
V_comp = rstTable.Fields(1).Value
End If
'Insert into table all the records
AppStr = "insert into " + rstResult.Source + " ( " + F_mabc + _
"," + F_comp + "," + F_tcost + "," + F_share + "," + F_cuco + _
"," + F_perc + "," + F_cumprc + ")"
ValStr = " Select '" + V_mabc + "','" + V_comp + "','" + V_tcost + _
"','" + V_share + "','" + V_cuco + "','" + V_perc + "','" + V_cumprc + "'"
'Concatenate the complete string to append a record to rstResult
AppSql = AppStr + ValStr
'set warnings off
DoCmd.SetWarnings False
DoCmd.RunSQL AppSql
rstTable.MoveNext
Wend
I'm a novice in VBA but I try to get a living out of it.
I want to append records in a table. But while doing it, an error came up.
There was a record with a null value.
To avoid problems I thought, maybe I can create a variable to check if the
value is realy null.
Now I'm facing an error telling me: "Object required" ;-(
Find here some code I've written. Can somebody help me out?
Dim V_mabc As String
Dim V_comp As String
Dim V_tcost As Single
Dim V_share As Single
Dim V_cuco As String
Dim V_perc As Single
Dim V_cumprc As Single
'Position on top of the table
rstTable.MoveFirst
'Run thru the table from begin to end
While Not rstTable.EOF
'For Each Field In rstTable.Fields
'First we fill up the variables
F_mabc = rstResult.Fields(0).Name
F_comp = rstResult.Fields(1).Name
F_tcost = rstResult.Fields(2).Name
F_share = rstResult.Fields(3).Name
F_cuco = rstResult.Fields(4).Name
F_perc = rstResult.Fields(5).Name
F_cumprc = rstResult.Fields(6).Name
'Values in variables
V_mabc = rstTable.Fields(0).Value
V_cumprc = "0"
'Check for null values
If rstTable.Fields(1).Value Is Null Then
V_comp = Space(0)
Else
V_comp = rstTable.Fields(1).Value
End If
'Insert into table all the records
AppStr = "insert into " + rstResult.Source + " ( " + F_mabc + _
"," + F_comp + "," + F_tcost + "," + F_share + "," + F_cuco + _
"," + F_perc + "," + F_cumprc + ")"
ValStr = " Select '" + V_mabc + "','" + V_comp + "','" + V_tcost + _
"','" + V_share + "','" + V_cuco + "','" + V_perc + "','" + V_cumprc + "'"
'Concatenate the complete string to append a record to rstResult
AppSql = AppStr + ValStr
'set warnings off
DoCmd.SetWarnings False
DoCmd.RunSQL AppSql
rstTable.MoveNext
Wend