Below is the vba code I am working with. When it gets to the insert part I get an "Enter parameter value" dialog box with the value of the variable "id" above the cursor. I have to type in that value so it is inserted in the table otherwise it insert a blank. What am I doing wrong?
Dim rs As ADODB.Recordset
Dim cmd As ADODB.Command
Dim query As String
Dim id As String
Dim begin_date As Date
Dim diff As Integer
DoCmd.SetWarnin gs False
DoCmd.RunSQL "insert into Items (item) select distinct part from [01 BO Table]"
query = "select distinct Item,Begin_Date from items"
DoCmd.SetWarnin gs True
Set cmd = New ADODB.Command
cmd.ActiveConne ction = CurrentProject. Connection
cmd.CommandText = query
Set rs = cmd.Execute()
While Not rs.EOF
id = rs.Fields(0)
begin_date = rs.Fields(1)
diff = DateDiff("d", begin_date, Date)
DoCmd.RunSQL "insert into [Tracking values](ItemTracked, Days_In_BO) select " + (id) + "," + CStr(diff)
rs.MoveNext
DoCmd.RunSQL "delete * from Items where Item not in (select part from [01 BO Table])"
'DoCmd.RunSQL "delete * from [Tracking Values] where ItemTracked not in (select part from [01 BO Table])"
Wend
rs.Close
Dim rs As ADODB.Recordset
Dim cmd As ADODB.Command
Dim query As String
Dim id As String
Dim begin_date As Date
Dim diff As Integer
DoCmd.SetWarnin gs False
DoCmd.RunSQL "insert into Items (item) select distinct part from [01 BO Table]"
query = "select distinct Item,Begin_Date from items"
DoCmd.SetWarnin gs True
Set cmd = New ADODB.Command
cmd.ActiveConne ction = CurrentProject. Connection
cmd.CommandText = query
Set rs = cmd.Execute()
While Not rs.EOF
id = rs.Fields(0)
begin_date = rs.Fields(1)
diff = DateDiff("d", begin_date, Date)
DoCmd.RunSQL "insert into [Tracking values](ItemTracked, Days_In_BO) select " + (id) + "," + CStr(diff)
rs.MoveNext
DoCmd.RunSQL "delete * from Items where Item not in (select part from [01 BO Table])"
'DoCmd.RunSQL "delete * from [Tracking Values] where ItemTracked not in (select part from [01 BO Table])"
Wend
rs.Close
Comment