T
Tcs
I want to create a temporary mdb just to hold the contents of one table. (It
will contain a LOT of records.) I'm assuming that creating a temporary db and
then deleting it when I'm done will be more expedient then merely deleting
records from a local table.
My problem is that I'm having difficulty with the proper syntax. Here's my
code:
Private Function fncOpenTempDatabase()
On Error GoTo Err_fncOpenTempDatabase
Set MyTempDatabase = "AS400_CIS_temp.mdb"
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists("AS400_CIS_temp.mdb") Then
Set db = CurrentDb
Set rs = db.OpenRecordset("tblAcctsRecAging_Details")
intNmbrOfRecs =
CurrentDb().TableDefs("tblAcctsRecAging_Details").RecordCount
rs.Close
Set db = Nothing
Forms!frmProgressBar.Caption = "Flushing table (1) of (4) - (" & _
intNmbrOfRecs & ") records to delete THIS table..."
DoEvents
Call fncDeleteTempDatabase(MyTempDatabase)
End If
Call fncCreateTempDatabase(MyTempDatabase)
Exit_fncOpenTempDatabase:
Exit Function
Err_fncOpenTempDatabase:
MsgBox "Error # " & Err.Number & " was generated by " & Err.Source & vbCrLf
& Err.Description, , "RunJob - fncOpenTempDatabase - " & Date & " - " & Time
' intRunJobLElecRpt4Andy = False
Resume Exit_fncOpenTempDatabase
End Function
With the following line in:
Set MyTempDatabase = "AS400_CIS_temp.mdb"
I get a compile error..."Type mismatch". I have to remove (or comment out) this
line to get the compiler to accept my code. BUT...how do I tell Access what the
name of my temp db is, so it'll deal with it, whether or not it has to delete it
before creating it?
ALSO...I want to create a table in the new db once I have created it. I have
this code:
Private Function fncCreateTable(MyTempDatabase As Database)
On Error GoTo Err_fncCreateTable
Dim MyTabledef As TableDef
oconn.open = & _
"Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=AS400_CIS_temp.mdb;" & _
"Exclusive=1;" & _
"Uid=admin;" & _
"Pwd="
Set dbODBC = OpenDatabase("", False, False, strConnect)
Set MyTabledef = MyTempDatabase.CreateTableDef("tblAcctsRecAging_Details")
MyTabledef.Connect = dbODBC.Connect
MyTabledef.SourceTableName = "tblAcctsRecAging_Details"
With MyTabledef
.Fields.Append .CreateField("CustID", dbDecimal)
.Fields.Append .CreateField("LocID", dbDecimal)
.Fields.Append .CreateField("CustClass", dbText, 2)
.Fields.Append .CreateField("Serv", dbText, 2)
.Fields.Append .CreateField("PeriodYY", dbLong)
.Fields.Append .CreateField("PeriodMM", dbLong)
.Fields.Append .CreateField("AgeCode", dbText, 4)
.Fields.Append .CreateField("ChgType", dbText, 2)
.Fields.Append .CreateField("ChgDesc", dbText, 20)
.Fields.Append .CreateField("CurrentCount", dbLong)
.Fields.Append .CreateField("CurrentAmtBilled", dbLong)
.Fields.Append .CreateField("CurrentUnPaid", dbLong)
.Fields.Append .CreateField("30dayCount", dbLong)
.Fields.Append .CreateField("30dayAmtBilled", dbLong)
.Fields.Append .CreateField("30dayUnPaid", dbLong)
.Fields.Append .CreateField("60dayCount", dbLong)
.Fields.Append .CreateField("60dayAmtBilled", dbLong)
.Fields.Append .CreateField("60dayUnPaid", dbLong)
.Fields.Append .CreateField("90dayCount", dbLong)
.Fields.Append .CreateField("90dayAmtBilled", dbLong)
.Fields.Append .CreateField("90dayUnPaid", dbLong)
.Fields.Append .CreateField("Over90Count", dbLong)
.Fields.Append .CreateField("Over90AmtBilled", dbLong)
.Fields.Append .CreateField("Over90UnPaid", dbLong)
.Fields.Append .CreateField("DateRetrieved", dbDate)
End With
' Add table to the collection.
MyTempDatabase.TableDefs.Append MyTabledef
MyTempDatabase.Close
Exit_fncCreateTable:
Exit Function
Err_fncCreateTable:
MsgBox "Error # " & Err.Number & " was generated by " & Err.Source & vbCrLf
& Err.Description, , "RunJob - fncCreateTable - " & Date & " - " & Time
' intRunJobLElecRpt4Andy = False
Resume Exit_fncCreateTable
End Function
The compiler doesn't like this part:
oconn.open = & _
"Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=AS400_CIS_temp.mdb;" & _
"Exclusive=1;" & _
"Uid=admin;" & _
"Pwd="
If I change "oconn" to "strConnect" I still get the same error. "Syntax error."
I'm thinking this is probably an ADO vs DAO issue, but I'm still learning the
differences, and don't really know.
I'm trying to open the database, create my table, then close the database.
(I'll open a recordset later.)
If anyone has any fixes/thoughts/suggestions/advice, all is welcome.
Thanks in advance,
Tom
will contain a LOT of records.) I'm assuming that creating a temporary db and
then deleting it when I'm done will be more expedient then merely deleting
records from a local table.
My problem is that I'm having difficulty with the proper syntax. Here's my
code:
Private Function fncOpenTempDatabase()
On Error GoTo Err_fncOpenTempDatabase
Set MyTempDatabase = "AS400_CIS_temp.mdb"
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists("AS400_CIS_temp.mdb") Then
Set db = CurrentDb
Set rs = db.OpenRecordset("tblAcctsRecAging_Details")
intNmbrOfRecs =
CurrentDb().TableDefs("tblAcctsRecAging_Details").RecordCount
rs.Close
Set db = Nothing
Forms!frmProgressBar.Caption = "Flushing table (1) of (4) - (" & _
intNmbrOfRecs & ") records to delete THIS table..."
DoEvents
Call fncDeleteTempDatabase(MyTempDatabase)
End If
Call fncCreateTempDatabase(MyTempDatabase)
Exit_fncOpenTempDatabase:
Exit Function
Err_fncOpenTempDatabase:
MsgBox "Error # " & Err.Number & " was generated by " & Err.Source & vbCrLf
& Err.Description, , "RunJob - fncOpenTempDatabase - " & Date & " - " & Time
' intRunJobLElecRpt4Andy = False
Resume Exit_fncOpenTempDatabase
End Function
With the following line in:
Set MyTempDatabase = "AS400_CIS_temp.mdb"
I get a compile error..."Type mismatch". I have to remove (or comment out) this
line to get the compiler to accept my code. BUT...how do I tell Access what the
name of my temp db is, so it'll deal with it, whether or not it has to delete it
before creating it?
ALSO...I want to create a table in the new db once I have created it. I have
this code:
Private Function fncCreateTable(MyTempDatabase As Database)
On Error GoTo Err_fncCreateTable
Dim MyTabledef As TableDef
oconn.open = & _
"Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=AS400_CIS_temp.mdb;" & _
"Exclusive=1;" & _
"Uid=admin;" & _
"Pwd="
Set dbODBC = OpenDatabase("", False, False, strConnect)
Set MyTabledef = MyTempDatabase.CreateTableDef("tblAcctsRecAging_Details")
MyTabledef.Connect = dbODBC.Connect
MyTabledef.SourceTableName = "tblAcctsRecAging_Details"
With MyTabledef
.Fields.Append .CreateField("CustID", dbDecimal)
.Fields.Append .CreateField("LocID", dbDecimal)
.Fields.Append .CreateField("CustClass", dbText, 2)
.Fields.Append .CreateField("Serv", dbText, 2)
.Fields.Append .CreateField("PeriodYY", dbLong)
.Fields.Append .CreateField("PeriodMM", dbLong)
.Fields.Append .CreateField("AgeCode", dbText, 4)
.Fields.Append .CreateField("ChgType", dbText, 2)
.Fields.Append .CreateField("ChgDesc", dbText, 20)
.Fields.Append .CreateField("CurrentCount", dbLong)
.Fields.Append .CreateField("CurrentAmtBilled", dbLong)
.Fields.Append .CreateField("CurrentUnPaid", dbLong)
.Fields.Append .CreateField("30dayCount", dbLong)
.Fields.Append .CreateField("30dayAmtBilled", dbLong)
.Fields.Append .CreateField("30dayUnPaid", dbLong)
.Fields.Append .CreateField("60dayCount", dbLong)
.Fields.Append .CreateField("60dayAmtBilled", dbLong)
.Fields.Append .CreateField("60dayUnPaid", dbLong)
.Fields.Append .CreateField("90dayCount", dbLong)
.Fields.Append .CreateField("90dayAmtBilled", dbLong)
.Fields.Append .CreateField("90dayUnPaid", dbLong)
.Fields.Append .CreateField("Over90Count", dbLong)
.Fields.Append .CreateField("Over90AmtBilled", dbLong)
.Fields.Append .CreateField("Over90UnPaid", dbLong)
.Fields.Append .CreateField("DateRetrieved", dbDate)
End With
' Add table to the collection.
MyTempDatabase.TableDefs.Append MyTabledef
MyTempDatabase.Close
Exit_fncCreateTable:
Exit Function
Err_fncCreateTable:
MsgBox "Error # " & Err.Number & " was generated by " & Err.Source & vbCrLf
& Err.Description, , "RunJob - fncCreateTable - " & Date & " - " & Time
' intRunJobLElecRpt4Andy = False
Resume Exit_fncCreateTable
End Function
The compiler doesn't like this part:
oconn.open = & _
"Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=AS400_CIS_temp.mdb;" & _
"Exclusive=1;" & _
"Uid=admin;" & _
"Pwd="
If I change "oconn" to "strConnect" I still get the same error. "Syntax error."
I'm thinking this is probably an ADO vs DAO issue, but I'm still learning the
differences, and don't really know.
I'm trying to open the database, create my table, then close the database.
(I'll open a recordset later.)
If anyone has any fixes/thoughts/suggestions/advice, all is welcome.
Thanks in advance,
Tom