Hi all. Am new to this site and to SQL so treat me with !!!
I have imported data from a MS ACCESS file. Not all of the data from the MS access table has been transfered to my sql tables. Septemebers data does not appear at all and Nov and Dec's data only shows data from 1st - 9th december !!! it should be from 1st - 31st dec. Lookin at the code i cannot work out why this is. I will paste the whole code in as i dont know which part of the code is causing the problem..
What i was thinking was to do a count statement which uses the msgbox function to pop up when a months data has been entered which tells me the total number of rows added for that month . This is So i can see whether the data has gone in, but dont know how to or where to place it
PLEASE PLEASE HELP
THE B****RD CODE
dim varLOOP
dim Sqlstring
dim SqlInsert
dim Conn
dim Rs
dim ConnWrite
dim objcmd
dim strconn
dim LpCount
dim var_day
dim var_month
dim var_year
dim var_logon_date
dim var_logoff_date
on error resume next
'***************************************************************************************************
*******************
'set variable
varLOOP = 1
'start loop for month value
Do until varLOOP =13
'***************************************************************************************************
*******************
'msgbox varLOOP
'build connection string to required DB
'work out month from loop counter
DBMonth = varLOOP
'if month is less than 10 then add a zero
if DBMonth < 10 then
DBMonth = "0" & DBMonth
end if
DBYear = "2002"
'create ms access db filename
accessDB = "histcrec" & DBMonth & DBYear & ".mdb"
strconn="PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE="
strconn=strconn & "Q:\rtarchdata\" & accessDB & ";"
'msgbox accessDB
'Build SQLstring
sqlstring = "select * from agentlogondata"
set Conn = createobject("adodb.connection"
set Rs = createobject("adodb.recordset"
Conn.open = strconn
Rs.open SqlString, Conn
LpCount = 0
err.clear
if Rs.eof then
set ConnWrite = createobject("adodb.connection"
ConnWrite.open = "DSN=CallScan"
Sqlinsert = SqlInsert & "insert into agentlogondataerr (agent_id)"
Sqlinsert = SqlInsert & "values ('0')"
ConnWrite.Execute(SQLinsert)
else:
set ConnWrite = createobject("adodb.connection"
ConnWrite.open = "DSN=CallScan"
do until Rs.eof
'Build a SQL insert string
SqlInsert = ""
Sqlinsert = SqlInsert & "(agent_id, group_id, turret_id, logon_date, logoff_date, "
Sqlinsert = SqlInsert & "logon_ddmmyyyy, logon_hhmmss, logoff_ddmmyyyy, logoff_hhmmss)"
Sqlinsert = SqlInsert & " values ('" & rs("agent_id"
& "', '" & rs("group_id"
& "', '" & rs("turret_id"
& "', '" & rs("logon_date"
& "', '" & rs("logoff_date"
& "', "
'build logon date
var_day = datepart ("d", rs("logon_date"
)
var_month = datepart ("m", rs("logon_date"
)
var_year = datepart ("yyyy", rs("logon_date"
)
Var_month = monthname(var_month)
var_logon_date = var_day & " " & var_month & " " & var_year
'logon date
sqlinsert = sqlinsert & "'" & var_logon_date & "', "
'logon date
sqlinsert = sqlinsert & "'" & datepart("h", rs("logon_date"
) & ":" & datepart("n", rs("logon_date"
) & ":" & datepart("s", rs("logon_date"
) & "', "
'build logoff date
var_day = datepart ("d", rs("logoff_date"
)
var_month = datepart ("m", rs("logoff_date"
)
var_year = datepart ("yyyy", rs("logoff_date"
)
var_month = monthname(var_month)
var_logoff_Date = var_day & " " & var_month & " " & var_year
sqlinsert = sqlinsert & "'" & var_logoff_date & "', "
sqlinsert = sqlinsert & "'" & datepart("h", rs("logoff_date"
) & ":" & datepart ("n", rs("logoff_date"
) & ":" & datepart ("s", rs("logoff_date"
) & "')"
ConnWrite.Execute("Insert into agentlogondata " & SQLinsert)
if err.number <> 0 then
ConnWrite.Execute("Insert into agentlogondataerr " & SQLinsert)
err.clear
end if
LPcount = LPcount + 1
Rs.movenext
loop
ConnWrite.close
set ConnWrite = nothing
end if
Rs.close
Conn.close
'***************************************************************************************************
*******************
'increment by one
varLOOP = varLOOP + 1
'end main loop
Loop
'***************************************************************************************************
*******************
'destroy connections
set Rs = nothing
set Conn = nothing
I have imported data from a MS ACCESS file. Not all of the data from the MS access table has been transfered to my sql tables. Septemebers data does not appear at all and Nov and Dec's data only shows data from 1st - 9th december !!! it should be from 1st - 31st dec. Lookin at the code i cannot work out why this is. I will paste the whole code in as i dont know which part of the code is causing the problem..
What i was thinking was to do a count statement which uses the msgbox function to pop up when a months data has been entered which tells me the total number of rows added for that month . This is So i can see whether the data has gone in, but dont know how to or where to place it
PLEASE PLEASE HELP
THE B****RD CODE
dim varLOOP
dim Sqlstring
dim SqlInsert
dim Conn
dim Rs
dim ConnWrite
dim objcmd
dim strconn
dim LpCount
dim var_day
dim var_month
dim var_year
dim var_logon_date
dim var_logoff_date
on error resume next
'***************************************************************************************************
*******************
'set variable
varLOOP = 1
'start loop for month value
Do until varLOOP =13
'***************************************************************************************************
*******************
'msgbox varLOOP
'build connection string to required DB
'work out month from loop counter
DBMonth = varLOOP
'if month is less than 10 then add a zero
if DBMonth < 10 then
DBMonth = "0" & DBMonth
end if
DBYear = "2002"
'create ms access db filename
accessDB = "histcrec" & DBMonth & DBYear & ".mdb"
strconn="PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE="
strconn=strconn & "Q:\rtarchdata\" & accessDB & ";"
'msgbox accessDB
'Build SQLstring
sqlstring = "select * from agentlogondata"
set Conn = createobject("adodb.connection"
set Rs = createobject("adodb.recordset"
Conn.open = strconn
Rs.open SqlString, Conn
LpCount = 0
err.clear
if Rs.eof then
set ConnWrite = createobject("adodb.connection"
ConnWrite.open = "DSN=CallScan"
Sqlinsert = SqlInsert & "insert into agentlogondataerr (agent_id)"
Sqlinsert = SqlInsert & "values ('0')"
ConnWrite.Execute(SQLinsert)
else:
set ConnWrite = createobject("adodb.connection"
ConnWrite.open = "DSN=CallScan"
do until Rs.eof
'Build a SQL insert string
SqlInsert = ""
Sqlinsert = SqlInsert & "(agent_id, group_id, turret_id, logon_date, logoff_date, "
Sqlinsert = SqlInsert & "logon_ddmmyyyy, logon_hhmmss, logoff_ddmmyyyy, logoff_hhmmss)"
Sqlinsert = SqlInsert & " values ('" & rs("agent_id"
'build logon date
var_day = datepart ("d", rs("logon_date"
var_month = datepart ("m", rs("logon_date"
var_year = datepart ("yyyy", rs("logon_date"
Var_month = monthname(var_month)
var_logon_date = var_day & " " & var_month & " " & var_year
'logon date
sqlinsert = sqlinsert & "'" & var_logon_date & "', "
'logon date
sqlinsert = sqlinsert & "'" & datepart("h", rs("logon_date"
'build logoff date
var_day = datepart ("d", rs("logoff_date"
var_month = datepart ("m", rs("logoff_date"
var_year = datepart ("yyyy", rs("logoff_date"
var_month = monthname(var_month)
var_logoff_Date = var_day & " " & var_month & " " & var_year
sqlinsert = sqlinsert & "'" & var_logoff_date & "', "
sqlinsert = sqlinsert & "'" & datepart("h", rs("logoff_date"
ConnWrite.Execute("Insert into agentlogondata " & SQLinsert)
if err.number <> 0 then
ConnWrite.Execute("Insert into agentlogondataerr " & SQLinsert)
err.clear
end if
LPcount = LPcount + 1
Rs.movenext
loop
ConnWrite.close
set ConnWrite = nothing
end if
Rs.close
Conn.close
'***************************************************************************************************
*******************
'increment by one
varLOOP = varLOOP + 1
'end main loop
Loop
'***************************************************************************************************
*******************
'destroy connections
set Rs = nothing
set Conn = nothing