W
Wes via AccessMonster.com
Very new to VB coding and looking for some insightful advice so that I don't
get into very many bad coding habits.
When I first jumped into this project I added autonumber to the table
"GroupFiles" so that there would be a key field, quickly found out that these
files would max out the 2 gig limit of Access very quickly (and these are the
small ones). Our CAD administrator then offered some space on the Oracle
server to hold the table. I accepted quickly dumped/exported Access table
into the Oracle table, then I found out that Oracle does not do autonumber.
This autonumber "problem" shows up by me having to go through some goat ropes
listed below. Thinking of just doing away with autonumber, but then I would
not have a "indexed (duplicates not OK)" field in the Oracle table, even
though I can't imagine what I would use it for. It does nothing but take up
space, but I have read that it is good database practise to have a key field.
Any thoughts would be appreciated...
Function Start_GF_Import()
'I am dealing with very large files/databases. So timing the 'procedure
satifies my curiosity.
Dim Msg, Style, Title, Response
Dim TimeStart As Single
Dim TimeEnd As Single
Dim timeElapsed As Single
'Have to reset table due to Oracle not having autonumber.
Msg = "Database MUST be compacted before import. Continue?"
Style = vbYesNo + vbCritical + vbDefaultButton2
Title = "This is crucial"
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
TimeStart = Timer
GF_Proc
TimeEnd = Timer
MsgBox ("Import finished")
End If
timeElapsed = Format(TimeEnd - TimeStart, "Fixed")
MsgBox ("The procedure took " & hns(timeElapsed) & " to run.")
End Function
Sub GF_Proc()
'Need to process raw data to comply with database standards. Actually,
getting field names right by replacing blanks with underscores. I wrote an
Excel macro to do this.
Dim myXL As Object
Dim mySS As Object
Set myXL = CreateObject("Excel.Application")
Set mySS = myXL.Workbooks.Open("C:\mypath\Config GFs Macro.xls")
myXL.Run "StartMe_Conf_GFs"
mySS.Close
myXL.Quit
Set mySS = Nothing
Set myXL = Nothing
'Have to get last "autonumber" from Oracle table.
DoCmd.OpenQuery "GFs_Sorted_Query", acViewNormal, acReadOnly
DoCmd.GoToRecord acDataQuery, "GFs_Sorted_Query", acLast
DoCmd.RunCommand acCmdCopy
DoCmd.Close acQuery, "GFs_Sorted_Query", acSaveNo
'Paste last "autonumber" from Oracle table into integer field in first
temp table.
DoCmd.OpenTable "z_groupfiles03", acViewNormal, acEdit
DoCmd.RunCommand acCmdPaste
DoCmd.Close acTable, "z_groupfiles03", acSaveYes
DoCmd.SetWarnings False
'Append single record with integer field into second temp table that has
autonumber.
DoCmd.OpenQuery "zGFs03_to_zGFs"
DoCmd.SetWarnings True
'Import processed data into second temp table.
ChDir "c:\temp"
myFile = Dir("*.xls")
Do Until myFile = ""
DoCmd.TransferSpreadsheet acImport, 8, "z_GroupFiles", myFile, True
Kill myFile
myFile = Dir("*.xls")
Loop
'Delete first autonumber in second temp table that was appended from
Oracle table
DoCmd.SetWarnings False
DoCmd.OpenTable "z_groupfiles", acViewNormal, acEdit
DoCmd.GoToRecord acDataTable, "z_groupfiles", acFirst
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.Close acTable, "z_groupfiles", acSaveYes
'Append data from second temp table into main Oracle table.
DoCmd.OpenQuery "zGFs_to_GFs_Append_Query"
'Delete data from first and second temp tables.
DoCmd.OpenQuery "z_GFs_Delete_Query"
DoCmd.OpenQuery "z_GFs03_Delete_Query"
DoCmd.SetWarnings True
End Sub
Swimming in the ocean of coding,
Wes
get into very many bad coding habits.
When I first jumped into this project I added autonumber to the table
"GroupFiles" so that there would be a key field, quickly found out that these
files would max out the 2 gig limit of Access very quickly (and these are the
small ones). Our CAD administrator then offered some space on the Oracle
server to hold the table. I accepted quickly dumped/exported Access table
into the Oracle table, then I found out that Oracle does not do autonumber.
This autonumber "problem" shows up by me having to go through some goat ropes
listed below. Thinking of just doing away with autonumber, but then I would
not have a "indexed (duplicates not OK)" field in the Oracle table, even
though I can't imagine what I would use it for. It does nothing but take up
space, but I have read that it is good database practise to have a key field.
Any thoughts would be appreciated...
Function Start_GF_Import()
'I am dealing with very large files/databases. So timing the 'procedure
satifies my curiosity.
Dim Msg, Style, Title, Response
Dim TimeStart As Single
Dim TimeEnd As Single
Dim timeElapsed As Single
'Have to reset table due to Oracle not having autonumber.
Msg = "Database MUST be compacted before import. Continue?"
Style = vbYesNo + vbCritical + vbDefaultButton2
Title = "This is crucial"
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
TimeStart = Timer
GF_Proc
TimeEnd = Timer
MsgBox ("Import finished")
End If
timeElapsed = Format(TimeEnd - TimeStart, "Fixed")
MsgBox ("The procedure took " & hns(timeElapsed) & " to run.")
End Function
Sub GF_Proc()
'Need to process raw data to comply with database standards. Actually,
getting field names right by replacing blanks with underscores. I wrote an
Excel macro to do this.
Dim myXL As Object
Dim mySS As Object
Set myXL = CreateObject("Excel.Application")
Set mySS = myXL.Workbooks.Open("C:\mypath\Config GFs Macro.xls")
myXL.Run "StartMe_Conf_GFs"
mySS.Close
myXL.Quit
Set mySS = Nothing
Set myXL = Nothing
'Have to get last "autonumber" from Oracle table.
DoCmd.OpenQuery "GFs_Sorted_Query", acViewNormal, acReadOnly
DoCmd.GoToRecord acDataQuery, "GFs_Sorted_Query", acLast
DoCmd.RunCommand acCmdCopy
DoCmd.Close acQuery, "GFs_Sorted_Query", acSaveNo
'Paste last "autonumber" from Oracle table into integer field in first
temp table.
DoCmd.OpenTable "z_groupfiles03", acViewNormal, acEdit
DoCmd.RunCommand acCmdPaste
DoCmd.Close acTable, "z_groupfiles03", acSaveYes
DoCmd.SetWarnings False
'Append single record with integer field into second temp table that has
autonumber.
DoCmd.OpenQuery "zGFs03_to_zGFs"
DoCmd.SetWarnings True
'Import processed data into second temp table.
ChDir "c:\temp"
myFile = Dir("*.xls")
Do Until myFile = ""
DoCmd.TransferSpreadsheet acImport, 8, "z_GroupFiles", myFile, True
Kill myFile
myFile = Dir("*.xls")
Loop
'Delete first autonumber in second temp table that was appended from
Oracle table
DoCmd.SetWarnings False
DoCmd.OpenTable "z_groupfiles", acViewNormal, acEdit
DoCmd.GoToRecord acDataTable, "z_groupfiles", acFirst
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.Close acTable, "z_groupfiles", acSaveYes
'Append data from second temp table into main Oracle table.
DoCmd.OpenQuery "zGFs_to_GFs_Append_Query"
'Delete data from first and second temp tables.
DoCmd.OpenQuery "z_GFs_Delete_Query"
DoCmd.OpenQuery "z_GFs03_Delete_Query"
DoCmd.SetWarnings True
End Sub
Swimming in the ocean of coding,
Wes