R
raymondp
I'm in the process of creating a code to copy and paste values within access
and then export the data to an excel worksheet. When I run the program, the
data that I want copied and pasted does so just fine. However, when the
module is done, access becomes unresponsive, forcing me to restart the entire
program. Can anyone tell me what's going on.
Also, I can't seem to figure out how to get access to open the excel
workbook to the correct worksheet and then paste in the new row of data at
the end of the existing data.
Below is the code I've written thus far. Any help you could provide would
be greatly appreciated.
'-----------------------------------------------------------
' Export_To_Excel
'
'-----------------------------------------------------------
Function Export_To_Excel()
On Error GoTo Export_To_Excel_Err
DoCmd.Echo False, "Macro is Running...Please Wait"
DoCmd.OpenForm "Ocean Sensor Stats Entry Form", acNormal, "", "",
acFormAdd, acWindowNormal
DoCmd.GoToRecord acForm, "Ocean Sensor Stats Entry Form", acNewRec
DoCmd.OpenForm "Form to Calculate Stats", acNormal, "", "",
acFormReadOnly, acWindowNormal
' 1.Copy and Paste ADCP Data
DoCmd.GoToControl "[NumADCPDep]"
DoCmd.RunCommand acCmdCopy
DoCmd.SelectObject acForm, "Ocean Sensor Stats Entry Form"
DoCmd.GoToControl "[ADCP's Deployed]"
DoCmd.RunCommand acCmdPaste
DoCmd.SelectObject acForm, "Form to Calculate Stats"
DoCmd.GoToControl "[PerADCPRep]"
DoCmd.RunCommand acCmdCopy
DoCmd.SelectObject acForm, "Ocean Sensor Stats Entry Form"
DoCmd.GoToControl "[% ADCP's Reporting]"
DoCmd.RunCommand acCmdPaste
' 2.Copy and Paste Salinity Data
DoCmd.SelectObject acForm, "Form to Calculate Stats"
DoCmd.GoToControl "[NumSalDep]"
DoCmd.RunCommand acCmdCopy
DoCmd.SelectObject acForm, "Ocean Sensor Stats Entry Form"
DoCmd.GoToControl "[Sal's Deployed]"
DoCmd.RunCommand acCmdPaste
DoCmd.SelectObject acForm, "Form to Calculate Stats"
DoCmd.GoToControl "[PerSalRep]"
DoCmd.RunCommand acCmdCopy
DoCmd.SelectObject acForm, "Ocean Sensor Stats Entry Form"
DoCmd.GoToControl "[% Sal's Reporting]"
DoCmd.RunCommand acCmdPaste
' 3.Copy and Paste Temperature Data
DoCmd.SelectObject acForm, "Form to Calculate Stats"
DoCmd.GoToControl "[NumTempDep]"
DoCmd.RunCommand acCmdCopy
DoCmd.SelectObject acForm, "Ocean Sensor Stats Entry Form"
DoCmd.GoToControl "[Temp's Deployed]"
DoCmd.RunCommand acCmdPaste
DoCmd.SelectObject acForm, "Form to Calculate Stats"
DoCmd.GoToControl "[PerTempRep]"
DoCmd.RunCommand acCmdCopy
DoCmd.SelectObject acForm, "Ocean Sensor Stats Entry Form"
DoCmd.GoToControl "[% Temp's Reporting]"
DoCmd.RunCommand acCmdPaste
' 4.Copy and Paste SCM Data
DoCmd.SelectObject acForm, "Form to Calculate Stats"
DoCmd.GoToControl "[NumSCMDep]"
DoCmd.RunCommand acCmdCopy
DoCmd.SelectObject acForm, "Ocean Sensor Stats Entry Form"
DoCmd.GoToControl "[SCM's Deployed]"
DoCmd.RunCommand acCmdPaste
DoCmd.SelectObject acForm, "Form to Calculate Stats"
DoCmd.GoToControl "[PerSCMRep]"
DoCmd.RunCommand acCmdCopy
DoCmd.SelectObject acForm, "Ocean Sensor Stats Entry Form"
DoCmd.GoToControl "[% SCM's Reporting]"
DoCmd.RunCommand acCmdPaste
' 5.Close Forms
DoCmd.Close acForm, "Form to Calculate Stats"
DoCmd.Close acForm, "Ocean Sensor Stats Entry Form"
' 6.Copy Stat Values
DoCmd.OpenQuery "Ocean Sensor Stats Query", acViewNormal, acReadOnly
DoCmd.RunCommand acCmdSelectAll
DoCmd.RunCommand acCmdCopy
' 7.Open Excel Spreadsheet
Dim objExcel As Object
Set objExcel = CreateObject("Excel.Application")
objExcel.Application.Workbooks.Open "C:\Documents and
Settings\raymondp\My Documents\Ocean Data
Availability\Ocean_data_availability.xls"
objExcel.Application.Visible = True
Export_To_Excel_Exit:
Exit Function
Export_To_Excel_Err:
MsgBox Error, vbOKOnly
Resume Export_To_Excel_Exit
End Function
and then export the data to an excel worksheet. When I run the program, the
data that I want copied and pasted does so just fine. However, when the
module is done, access becomes unresponsive, forcing me to restart the entire
program. Can anyone tell me what's going on.
Also, I can't seem to figure out how to get access to open the excel
workbook to the correct worksheet and then paste in the new row of data at
the end of the existing data.
Below is the code I've written thus far. Any help you could provide would
be greatly appreciated.
'-----------------------------------------------------------
' Export_To_Excel
'
'-----------------------------------------------------------
Function Export_To_Excel()
On Error GoTo Export_To_Excel_Err
DoCmd.Echo False, "Macro is Running...Please Wait"
DoCmd.OpenForm "Ocean Sensor Stats Entry Form", acNormal, "", "",
acFormAdd, acWindowNormal
DoCmd.GoToRecord acForm, "Ocean Sensor Stats Entry Form", acNewRec
DoCmd.OpenForm "Form to Calculate Stats", acNormal, "", "",
acFormReadOnly, acWindowNormal
' 1.Copy and Paste ADCP Data
DoCmd.GoToControl "[NumADCPDep]"
DoCmd.RunCommand acCmdCopy
DoCmd.SelectObject acForm, "Ocean Sensor Stats Entry Form"
DoCmd.GoToControl "[ADCP's Deployed]"
DoCmd.RunCommand acCmdPaste
DoCmd.SelectObject acForm, "Form to Calculate Stats"
DoCmd.GoToControl "[PerADCPRep]"
DoCmd.RunCommand acCmdCopy
DoCmd.SelectObject acForm, "Ocean Sensor Stats Entry Form"
DoCmd.GoToControl "[% ADCP's Reporting]"
DoCmd.RunCommand acCmdPaste
' 2.Copy and Paste Salinity Data
DoCmd.SelectObject acForm, "Form to Calculate Stats"
DoCmd.GoToControl "[NumSalDep]"
DoCmd.RunCommand acCmdCopy
DoCmd.SelectObject acForm, "Ocean Sensor Stats Entry Form"
DoCmd.GoToControl "[Sal's Deployed]"
DoCmd.RunCommand acCmdPaste
DoCmd.SelectObject acForm, "Form to Calculate Stats"
DoCmd.GoToControl "[PerSalRep]"
DoCmd.RunCommand acCmdCopy
DoCmd.SelectObject acForm, "Ocean Sensor Stats Entry Form"
DoCmd.GoToControl "[% Sal's Reporting]"
DoCmd.RunCommand acCmdPaste
' 3.Copy and Paste Temperature Data
DoCmd.SelectObject acForm, "Form to Calculate Stats"
DoCmd.GoToControl "[NumTempDep]"
DoCmd.RunCommand acCmdCopy
DoCmd.SelectObject acForm, "Ocean Sensor Stats Entry Form"
DoCmd.GoToControl "[Temp's Deployed]"
DoCmd.RunCommand acCmdPaste
DoCmd.SelectObject acForm, "Form to Calculate Stats"
DoCmd.GoToControl "[PerTempRep]"
DoCmd.RunCommand acCmdCopy
DoCmd.SelectObject acForm, "Ocean Sensor Stats Entry Form"
DoCmd.GoToControl "[% Temp's Reporting]"
DoCmd.RunCommand acCmdPaste
' 4.Copy and Paste SCM Data
DoCmd.SelectObject acForm, "Form to Calculate Stats"
DoCmd.GoToControl "[NumSCMDep]"
DoCmd.RunCommand acCmdCopy
DoCmd.SelectObject acForm, "Ocean Sensor Stats Entry Form"
DoCmd.GoToControl "[SCM's Deployed]"
DoCmd.RunCommand acCmdPaste
DoCmd.SelectObject acForm, "Form to Calculate Stats"
DoCmd.GoToControl "[PerSCMRep]"
DoCmd.RunCommand acCmdCopy
DoCmd.SelectObject acForm, "Ocean Sensor Stats Entry Form"
DoCmd.GoToControl "[% SCM's Reporting]"
DoCmd.RunCommand acCmdPaste
' 5.Close Forms
DoCmd.Close acForm, "Form to Calculate Stats"
DoCmd.Close acForm, "Ocean Sensor Stats Entry Form"
' 6.Copy Stat Values
DoCmd.OpenQuery "Ocean Sensor Stats Query", acViewNormal, acReadOnly
DoCmd.RunCommand acCmdSelectAll
DoCmd.RunCommand acCmdCopy
' 7.Open Excel Spreadsheet
Dim objExcel As Object
Set objExcel = CreateObject("Excel.Application")
objExcel.Application.Workbooks.Open "C:\Documents and
Settings\raymondp\My Documents\Ocean Data
Availability\Ocean_data_availability.xls"
objExcel.Application.Visible = True
Export_To_Excel_Exit:
Exit Function
Export_To_Excel_Err:
MsgBox Error, vbOKOnly
Resume Export_To_Excel_Exit
End Function