2009-07-09 14 views
0

Oracleデータベースとワークシートからの照会を自動化するVBAを介してリコンシリエーションツールを構築しています。私がクエリを実行するとき、私はユーザに何のITEM(この場合はパイプライン)を問い合わせるか(ワークシートには多くの項目がある)と終了/開始日を入力させたい。私はトラブル次のことを考え出すを持っています:VBAの文字列から日付への変換とオートメーションプログラムのための古いSQLデータ出力のクリア

1)照会している - 返された値がNULLであれば、私はプリントアウトして、それを伝えることがどのように「DATAを使用できません」
2)どのように私は片付けることができますパイプラインAからの古いSQL文/データ出力、パイプラインBを照会していますか?
3)私の日付はOracleの文字列として保存されていますが、その日付をどのように変換できますか?
ありがとうございます!ここで

は、私がこれまで持っているものです。

また
Option Explicit 
Option Base 1 

Dim cnnObject As ADODB.Connection 
Dim rsObject As ADODB.Recordset 
Dim strGPOTSConnectionString As String 

Dim Pipeline As String 
Dim DateStart As Date 
Dim DateEnd As Date 
Dim strQuery As String 

Sub ClickButton2() 

Debug.Print ("Button has been clicked") 
Pipeline = InputBox("Enter PipeLine", "My Application", "Default Value") 
DateStart = InputBox("Enter Start Date", "My Application", DateTime.Date) 
DateEnd = InputBox("Enter End Date", "My Application", DateTime.Date + 1) 

Range("B1").Value = Pipeline 
Range("B2").Value = DateStart 
Range("B3").Value = DateEnd 

strQuery = "select pipelineflow.lciid lciid, ldate, volume, capacity, status, " & _ 
"pipeline, station, stationname, drn, state, county, owneroperator, companycode, " & _ 
"pointcode, pointtypeind, flowdirection, pointname, facilitytype, pointlocator, " & _ 
"pidgridcode from pipelineflow, pipelineproperties " & _ 
"where pipelineflow.lciid = pipelineproperties.lciid " & _ 
"and pipelineflow.audit_active = 1 " & _ 
"and pipelineproperties.audit_active =1 " & _ 
"and pipelineflow.ldate >= '" & Format(DateStart, "dd-MMM-yyyy") & "' and pipelineflow.ldate < '" & Format(DateEnd, "dd-MMM-yyyy") & "' " & _ 
"and pipelineproperties.pipeline = '" & Pipeline & "' " 


    Call PullZaiNetData(strQuery) 

    Call TieOut 

End Sub 

Sub PullZaiNetData2(ByVal strQry As String) 

    Set cnnObject = New ADODB.Connection 
    Set rsObject = New ADODB.Recordset 

    strGPOTSConnectionString = "DRIVER={Microsoft ODBC for Oracle}; SERVER=XYZ; PWD=XYZ; UID=XYZ" 


    cnnObject.Open strGPOTSConnectionString 

    rsObject.Open strQry, cnnObject, adOpenStatic 
    Worksheets("ZaiNet Data").Cells(1, 1).CopyFromRecordset rsObject 


    rsObject.Close 
    cnnObject.Close 

    Set rsObject = Nothing 
    Set cnnObject = Nothing 

End Sub 

Sub TieOut() 

End Sub 

私は、私が代わりに促されているのセルにユーザー入力の日付とパイプラインを聞かせてかもしれませんどのように、周りのものを変更したい場合は?

startDate = Worksheets("Instructions").Cells(5, 4).Value 

これは可能でしょうか?

答えて

1
  1. nullを置き換えるには、OracleのNVL機能を使用できます。例えば"NVL(pipelineflow.lciid、 'データがない')をSELECT ..."

  2. を使用すると、ワークシート( "ZaiNetデータ")を使用することができ、古いデータを消去する。Cells.Clear

  3. 変換するには日付の日付文字列はOracleのTO_DATE関数を使用します。 "SELECT TO_DATE(ldate、 'dd-mon-yyyy')..."となります。ここで、dd-mon-yyyyはデータベース内の日付文字列の日付形式です。

セルの値を日付にキャストできる限り、ワークシートから日付を読み取るコードは機能します。ワークシートの検証を使用して、ユーザーが有効な日付のみを入力できるようにすることができます。

関連する問題