Wrox Programmer Forums
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 26th, 2009, 01:30 AM
Registered User
 
Join Date: Aug 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default VB Sql Function

I have a program that gets data from an sql server but when i add new items the code beggins to have an error

Code:
Private Sub TlSiExcel()
Dim adoRs As New ADODB.Recordset
Dim exl, xlbook, xlsht
Dim strSQl As String, dteFrom As String, dteTo As String, phase As String

dteFrom = Format(dtFrom.Value, "yyyy/mm/dd")
dteTo = Format(dtTo.Value, "yyyy/mm/dd")

If optPhase(0).Value = True Then
    phase = 1
Else
    phase = 2
End If

strSQl = "select distinct testdate, (select testvalue from qa_wl_tl_results a where paramname ='Silane_Si' and a.tlId = tempd.tlId ) Silane_Si, " & _
            "(select testvalue from qa_wl_tl_results a where paramname ='Silane_pH' and a.tlId = tempd.tlId ) Silane_pH, " & _
            "(select testvalue from qa_wl_tl_results a where paramname ='Silane_Si 3' and a.tlId = tempd.tlId ) Silane_Si3, " & _
            "(select testvalue from qa_wl_tl_results a where paramname ='Silane_pH 3' and a.tlId = tempd.tlId ) Silane_pH3 From " & _
            "(select a.tlid,testdate,phase,paramname,testvalue from qa_wl_TlAnalysis a,qa_wl_tl_results b " & _
            "where a.tlid= b.tlid and phase ='" & phase & "' and a.tlid not like '%4h%' and (cast(testdate as char(20)) like '%6:00AM' or cast(testdate as char(20)) like '%10:00PM') " & _
            "and convert(char(10),testdate,111) between '" & dteFrom & "' and '" & dteTo & "') tempd"

OpenRecSet adoRs, strSQl

If Not adoRs.EOF Then

    Set exl = CreateObject("Excel.application")
    Set xlbook = exl.Workbooks.Open(App.Path & "\Reports\Monthly.xlt")
    Set xlsht = xlbook.Sheets("TLSi")
    
    xlsht.Activate
    xlsht.Cells(4, 1).CopyFromRecordset adoRs
    exl.Sheets("TRCF").Visible = xlSheetHidden
    exl.Sheets("TL12H").Visible = xlSheetHidden
    exl.Sheets("TL8H").Visible = xlSheetHidden
    exl.Sheets("TL4H").Visible = xlSheetHidden
    exl.Sheets("Chrome").Visible = xlSheetHidden
    exl.Sheets("EFC").Visible = xlSheetHidden
    exl.Sheets("Upinorg").Visible = xlSheetHidden
    xlsht.Name = "Phase " & phase
    'xlsht.Cells.Select
    'xlsht.Cells.EntireColumn.AutoFit
    xlsht.range("A4:A65536").Select
    exl.Selection.NumberFormat = "m/d/yyyy h:mm AM/PM;@"
    xlsht.Cells(4, 1).Select
    exl.Application.Visible = True
Else
    MsgBox "No Record Found!", vbInformation
End If
adoRs.Close

End Sub
pls check if i have mistake
 
Old August 28th, 2009, 09:37 AM
Authorized User
 
Join Date: Mar 2009
Posts: 49
Thanks: 0
Thanked 8 Times in 8 Posts
Default

Where do you get the error? What line? What is the error number and error description?





Similar Threads
Thread Thread Starter Forum Replies Last Post
conver VB function to c# Hughesie78 C# 11 April 25th, 2008 05:08 AM
Function in VB Manisha0605 .NET Framework 1.x 3 February 4th, 2007 11:04 AM
Need some help with a VB function crowsfan31 Beginning VB 6 1 June 19th, 2006 02:36 PM
How to call javascript function from VB function vinod_yadav1919 VB How-To 0 February 13th, 2006 06:03 AM
Function Iff in VB 6.0 daninoj Beginning VB 6 2 January 17th, 2005 01:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.