View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
[email protected] jferree@gmail.com is offline
external usenet poster
 
Posts: 2
Default ODBC query excluding headers

Hi,

Can someone tell me how to exclude the header or titles from the
results of an ODBC query against a MySQL DB.

Here is my code in case someone else would like to use it.

Sub get_oem_data(RowIndex, LastRowOfData, Program)

Dim oemConn As String
Dim oemSql As String
Dim oQt As QueryTable
Dim start_row As Integer

Application.StatusBar = "Clean out old OEM Data"
Sheets("oem_data").Select
current_sheet = ActiveSheet.Name
'LastRealCell_ftr =
RealLastCell(Sheets("Insp_data")).Address(RowAbsol ute:=False,
ColumnAbsolute:=False)
'Range("A1", LastRealCell_ftr).Select
'Range("A1", "IV6536").Select
Columns("A:IV").Select
Selection.ClearContents
'Selection.Delete Shift:=xlShiftToLeft
Cells.Select
Range("IV1").Activate
Selection.Clear


oemConn = "ODBC;DATABASE=databaseName;DESCRIPTION=MySQL ODBC 3.51
Drive
DSN;DSN=DSNConnectionName;OPTION=0;;PORT=0;SERVER= server.com;UID=userlogin"

Sheets("variables").Select

oemSql = "SELECT * "

oemSql = oemSql & "FROM aces_data.oem_data_fpm oem_data_fpm_0 "

oemSql = oemSql & "WHERE 1 AND ( ( "

If (RowIndex < start_row) Then

oemSql = oemSql & " OR ( "
End If

If (Cells(RowIndex, "C").Value < "") Then
oemSql = oemSql & " AND oem_data_fpm_0.Program=" & "'"
oemSql = oemSql & Cells(RowIndex, "C") & "'"
End If

oemSql = oemSql & " ) "


oemSql = oemSql & " ) "

oemSql = oemSql & " ORDER BY oem_data_fpm_0.id "
'MsgBox oemSql
Sheets("oem_data").Select
Cells(LastRowOfData, "A").Value = oemSql

If (LastRowOfData < 1) Then
LastRowOfData = LastRowOfData + 1
End If
insert_here_cell = "A" & LastRowOfData
Set oQt = ActiveSheet.QueryTables.Add( _
Connection:=oemConn, _
Destination:=Range(insert_here_cell), _
Sql:=oemSql)

oQt.Refresh BackgroundQuery:=False ' explicitly set background off
Call move_oem_data_to_tcgaz_sheet
End Sub