I have VBS code in an html page that gets queries from an access database. I am trying to print the result of a query at the right place in the html using
document.write(fDateDispo & " et " & tDateDispo)
where fDateDispo and tDateDispo are public variables declared before all subs in the program. In one of my procedure (declared Public Sub) I give the public vars their values with the query result. I used a msgbox() to confirm that the right values are attributed when the procedure runs.
My problem is that the value I give to the public variables during the procedure doesn’t stay after it has been executed, they are just empty and only the “et” gets printed.
[EDIT]
here is the code:
public sub SendQuery(DateOne,DateTwo)
On Error Resume Next
dim rs, passerelle, nbrAppels, c, stSQLpass
dim Objet, nbrObjet, stSQLobj, rsObj
dim Panne, nbrPanne, stSQLpan, rsPan
dim SQLfromDate, SQLtoDate, stWhere, FromDate, ToDate
SQLfromDate="SELECT Min(Avis.[Date Appel]) AS [MinDeDate Appel] FROM Avis;"
SQLtoDate="SELECT Max(Avis.[Date Appel]) AS [MaxDeDate Appel] FROM Avis;"
ADOConnection1.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=G:\Planification\Planification\Stagiaires\Sébastien Leblanc\EntretienElectro_Backup2.mdb"
Set FromDate = ADOConnection1.Execute(SQLfromDate)
Set ToDate = ADOConnection1.Execute(SQLtoDate)
fDateDispo=FromDate.Fields(0).Value
tDateDispo=ToDate.Fields(0).Value
With rs
.MoveFirst
Do While Not .EOF
passerelle = passerelle & .Fields(1).Value & Chr(9)
nbrAppels = nbrAppels & .Fields(0).Value & Chr(9)
.MoveNext
Loop
.Close
End With
' Remove the leftover tab character at the end of the strings.
passerelle = Left(passerelle, Len(passerelle) - 1)
nbrAppels = Left(nbrAppels, Len(nbrAppels) - 1)
' Objet cahrtspace1
With ChartSpace1
.Clear
.Charts.Add
Set c = .Constants
.AllowFiltering = True
.Interior.Color = "white"
With .Charts(0)
.Border.Color = "white"
.Interior.Color = "white"
.Axes(0).Hastitle = TRUE
.Axes(0).Title.Caption = "Passerelles" 'titre de l'axes des x
.Axes(1).Hastitle = TRUE
.Axes(1).Title.Caption = "Nombre d'Appels" 'titre de l'axe des y
.SeriesCollection.Add
.PlotArea.Interior.Color = "white" du graph
With .SeriesCollection(0)
.Interior.Color = RGB(61, 166, 228)
.SetData c.chDimCategories, c.chDataLiteral, nbrAppels
.SetData c.chDimValues, c.chDataLiteral, passerelle
End With
.Type = c.chChartTypeColumnClustered
End With
End With
ADOConnection1.Close
End sub
i left out a couple of things because I doubt it has anything to do with it. its just other OWC objects and stuff…
I tried just attributing a value by doing fDateDispo="date" in the sub, but no luck.
[EDIT 2]
This is client-side VBscript. The sub is in the <head> and the document write is in the <body> of the html.the sub is called by an other sub set as window_load event.
[EDIT 3]
here is where i place my document.write() :
<P style="PAGE-BREAK-AFTER: auto"><FONT face=Arial> Les
données entre les dates
<SCRIPT language=vbscript>
Document.write(fDateDispo & " et " & tDateDispo)
</SCRIPT>
sont disponibles.</FONT></P>
Hopefully I’m following this correctly, but to illustrate my comment:
when loaded, the output is
meaning that the
document.write()is called beforeloadhandler(), which is whyvarisEmptyin the first line in the output