Pick List is displaying but cannot pick from

Pick List is displaying but cannot pick from

Post by Jule » Thu, 01 Dec 2005 20:27:27


New to VBScript.

I've written a script which brings back a list of recent entires, the
idea beign our users pick the one they require rather than having to
remember their references. I've got the list to display but it doesn't
allow them to click on any. Code is below, where ABCDEF is our
database. Appreciate your help here, thanks.
-----------------------------------------------------------
sub main()

Set cnABCDEF = CreateObject("ADODB.Connection")

cnABCDEF.ConnectionString =
"ODBC;DATABASE=ABCDEF;DSN=ABCDEF;UID=xxx;PWD=xxx;APP=ABCDEF"

cnABCDEF.Open

Set cmdQuery = CreateObject ("ADODB.Command")
With cmdQuery
Set .ActiveConnection = cnABCDEF
.CommandText = "Select mattercode, matter from vw_refno where fe =
'JEH' and status = 'O' order by lasttime"
.CommandType = adCmdText
End With

Set matters = CreateObject("ADODB.Recordset")
Set matters.Source = cmdQuery
matters.Cursortype = adOpenForwardOnly
matters.CursorLocation = adUseClient
matters.LockType = adLockReadOnly
matters.Open

If matters.State = adStateOpen Then
Do While Not matters.EOF


strMsg = strMsg & matters.Fields("mattercode").Value
strMsg = strMsg & ":" & vbTab
strMsg = strMsg & matters.Fields("matter").Value
strMsg = strMsg & vbNewLine

matters.MoveNext
Loop
Matters.Close

MsgBox strMsg
Else
MsgBox "Recordset not opened"
End If

Set matters = Nothing
Set cmdQuery = Nothing
cnABCDEF.Close
Set cnABCDEF = Nothing

end sub
 
 
 

Pick List is displaying but cannot pick from

Post by Jule » Thu, 01 Dec 2005 23:52:26

Seems my code will only populate a static box and I need combo box
(wish it was easier to know what these things were called - picklists,
dropdown lists, listbox <sigh>). Can anyone how to use the combobox
code and what variables need declaring?

 
 
 

Pick List is displaying but cannot pick from

Post by Miyah » Fri, 02 Dec 2005 00:32:20


Use HTA.
Here is an example to use 'Select' element.

<!-- FileName : ComTimeE.hta -->
<html><head>
<hta:application applicationname="CommTime" singleinstance="yes"
scroll="no" sysmenu="no"/>
<title>Communication Time Calculator</title>
<script language=vbs>
Option Explicit
Const W = 380, H = 200: Dim Form
With window
.resizeTo W, H
.moveTo (screen.availwidth - W) \ 2, (screen.availheight - H) \ 2
End With
Sub Initialize
Dim StartDate, StartY, StartM, aOption, I
Set Form = document.all: StartDate = DateAdd("m", -1, Now)
StartY = Year(StartDate): StartM = Month(StartDate)
With Form
SetOption .LBY, Array(StartY, StartY + 1)
SetOption .LBM, Array(StartM, StartM + 1)
SetOption .LBD, Array(1, 6, 11, 16, 21, 26)
.LBD.Options(3).selected = True
SetOption .LBU, Array(1, 10, 20, 30, 60, 180)
End With
End Sub
'
Sub SetOption(Target, arVal)
Dim I, aOption
For I = 0 To UBound(arVal)
Set aOption = document.createElement("option")
Target.Options.Add aOption
aOption.innertext = arVal(I): aOption.value = arVal(I)
Next
End Sub
'
Sub CalcTime
Const Offset = 0' Time difference
Dim sDate, sWQL, cEvents, aEvent, DT, ST, TT
With Form
sDate = DateSerial(.LBY.value, .LBM.value, .LBD.value)
End With
sDate = "'" & Replace(DateAdd("h", Offset, sDate), "/", "-") & "'"
sWQL = "Select * from Win32_NTLogEvent Where Logfile = 'System'" _
& " And SourceName = 'RemoteAccess' And TimeWritten > " & sDate
Set cEvents = GetObject("winmgmts:\\.\root\cimv2").ExecQuery(sWQL)
For Each aEvent In cEvents
DT = Split(aEvent.TimeWritten, "+")(0)
DT = Left(DT, 4) & "/" & Mid(DT, 5, 2) & "/" & Mid(DT, 7, 2) & _
" " & Mid(DT, 9, 2) & ":" & Mid(DT, 11, 2) & ":" & Mid(DT, 13, 2)
DT = CDate(DT)
Select Case aEvent.EventCode
Case 20158
TT = DateAdd( _
"s", Ceiling(DateDiff("s", DT, ST), Form.LBU.Value), TT)
Case 20159: ST = DT
End Select
Next
Form.Lbl1.InnerText = _
Int(TT*24) & Right(FormatDateTime(TT, vbLongTime), 6)
End Sub
'
Function Ceiling(X, Unit)
Ceiling = ((X + Unit - 1) \ Unit) * Unit
End Function
'
</script></head><body onload=Initialize><form><p>
Start Date:Y
<select id=LBY></select>M<select id=LBM></select>
D<select id=LBD></select></p>
<p>Calculation Unit:<select id=LBU></select>Second</p>
<p align=center>
<input type=button id=CB1 value=Execute onclick=CalcTime>
    
<input type=button id=CB2 value=Close onclick=Close></p>
<p>      Total Communication Time :
<label id=LBL1><label></p>
</form></body></html>

--
Miyahn (Masataka Miyashita) JPN
Microsoft MVP for Microsoft Office - Excel(Jan 2005 - Dec 2005)
XXXX@XXXXX.COM