Norie - nice hearing from you.
A piece of the code
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim MySQLcheck As String
Dim i, j As Long
Dim rng As Range
Dim FieldCount, RowCount, tbcount, cbc As Integer
Dim rcArray As Variant
Sub Button1_Click()
Sheets("sheet1").Range("A3:Z10000").ClearContents
Sheets("sheet1").Range("A3:Z10000").Font.Bold = False
Range("A3").Select
Range("A3").Value = "Customer Requirements"
Selection.Font.Bold = True
Set rst = New ADODB.Recordset
Set cnn = New ADODB.Connection
MySQLcheck = "Select * from CUS_REQ"
With cnn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=N:\opr\database.mdb;"
.Open
End With
rst.Open MySQLcheck, cnn, adOpenStatic
RowCount = (rst.RecordCount)
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
If RowCount = 0 Then GoTo error1
Set cnn = New ADODB.Connection
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=N:\opr\database.mdb"
MySQLcheck = "SELECT [WAREHOUSE],[PARTNUMBER],[ORDER_NUM],[TRANS_DESC],[QUANTITY],[AVAIL_QTY],CDate([ENTER_DATE]),CDate([TRANS_DATE]) from CUS_REQ"
Set rst = cnn.Execute(MySQLcheck)
FieldCount = (rst.Fields.Count)
rst.MoveFirst
For i = 0 To FieldCount - 1
With Sheets("Sheet1").Range("A3").Offset(0, i)
.Value = rst.Fields(i).Name
End With
Next i
ActiveSheet.Range("A4").CopyFromRecordset rst
cnn.Close
Set rst = Nothing
Set cnn = Nothing
Selection.End(xlDown).Select
error1:
ActiveCell.Offset(2, 0).Select
'/////////////////////////////////////////////////////////////////////////////////////////////
ActiveCell.Value = "On Hand"
Selection.Font.Bold = True
Set rst = New ADODB.Recordset
Set cnn = New ADODB.Connection
MySQLcheck = "Select * from ON_HAND"
With cnn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=N:\opr\database.mdb;"
.Open
End With
rst.Open MySQLcheck, cnn, adOpenStatic
RowCount = (rst.RecordCount)
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
If RowCount = 0 Then GoTo error2
ActiveCell.Offset(1, 0).Select
Set cnn = New ADODB.Connection
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=N:\opr\database.mdb"
MySQLcheck = "SELECT [WAREHOUSE],[PARTNUMBER],[QUANTITY] from ON_HAND"
Set rst = cnn.Execute(MySQLcheck)
FieldCount = (rst.Fields.Count)
rst.MoveFirst
For i = 0 To FieldCount - 1
With ActiveCell.Offset(0, i)
.Value = rst.Fields(i).Name
End With
Next i
ActiveCell.Offset(1, 0).Select
ActiveCell.Offset(0, 0).CopyFromRecordset rst
cnn.Close
Set rst = Nothing
Set cnn = Nothing
If RowCount = 1 Then GoTo error2
Selection.End(xlDown).Select
error2:
ActiveCell.Offset(2, 0).Select