Ok,
You must replace
"myServer" with your SQL Server name or IP,
"myDataBase" with your Database
"myUsername" with your SQL user
"myPassword" with your SQL password
I fixed the syntax error.
(I don't have VB6 installed)
Please let me know.
-
Private Function GetValue() as string
-
on error goto EH
-
dim cn as object
-
dim rs as object
-
dim strSQL as string
-
GetValue = ""
-
set cn = createobject("adodb.connection")
-
set rs = createobject("adodb.recordset")
-
cn.open "Driver={SQL Server};Server=myServer;Database=myDataBase ;Uid=myUsername;Pwd=myPassword;"
-
strSQL = "Select creditamt from all_trlbal where clcode=101"
-
rs.open strSQL, cn, adOpenStatic, adLockReadOnly
-
if not (rs.bof and rs.eof) then
-
rs.movefirst
-
GetValue = val("" & rs(0))
-
end if
-
rs.close
-
cn.close
-
PreExit:
-
set rs = nothing
-
set cn = nothing
-
exit function
-
EH:
-
msgbox err.number & ": " & err.description
-
resume PreExit
-
end function
-
-
private sub cmdButton_Click()
-
txtAmount.text = GetValue()
-
end sub
-