Global is a legacy keyword from VB that is preserved for backwards compatibility, but has been replaced by Public.
strs and sh are used exclusively in Sub WriteData. I see no need for them to be Public.
I do not see how (or why) you are using the Attribute keyword here.
Insert blue code, delete red code.
' DataCycle module
Attribute VB_Name = "DataCycle" ' ?????
Option Explicit
Global sh As Object
Global strs As Object
Sub DataCycle()
[snip]
Call WriteStatus
[snip]
End Sub
' Status module
Attribute VB_Name = "Status" ' ?????
Option Explicit
Dim StatusQuery As String
Sub WriteStatus()
'====================================================================================
'This subroutine inserts into SQL Server one record from "status" data table in Excel
'====================================================================================
Dim sh As Object
Dim strs As Object
Dim StatusQuery As String
' Excel worksheet that contains the source data
Set sh = Worksheets("12_status")
' Transfer status data
StatusQuery = "test_data.data_status"
Set strs = CreateObject("ADODB.Recordset")
With strs
.Open StatusQuery, conn, 1, 3
.AddNew
.Fields("test_run_num").Value = sh.Cells(9, 1).Value
.Fields("data_status").Value = sh.Cells(9, 2).Value
.Fields("report_status").Value = sh.Cells(9, 3).Value
.Fields("sn_label_status").Value = sh.Cells(9, 4).Value
.Fields("flag_tag_status").Value = sh.Cells(9, 5).Value
.Fields("metal_tag_status").Value = sh.Cells(9, 6).Value
.Update
.Close
End With
Set sh = Nothing
Set strs = Nothing
End Sub
Sub Auto_Close()
[snip]
Set sh = Nothing
Set strs = Nothing
[snip]
End Sub
Bookmarks