ASP Classic "Microsoft VBScript runtime error '800a01a8' Object required: 'hashHelp'" - vbscript

Here I have a double Directory that is suppose to be carrying information from a database in the form of the object hashHelp. Clearly, this isn't working.
Based on everything I've found on this website and around the web, this error message seems to imply that the object hashHelp isn't being created, but you can clearly see it being created above. I have check Any idea what could be happening?
do until rs.eof
if valid(cart, rs, data) = true then
Dim hashHelp
Set hashHelp = new HashHelper
hashHelp.setCode(rs.Fields("Code"))
hashHelp.setDateTime(rs.Fields("ScanTime"))
Dim entry
entry = DateDiff("d", beginDate, DateValue(rs.Fields("ScanTime")))
hash.Item(rs.Fields("ScanTime")).Item(arr(entry)) = hashHelp
arr(DateDiff("d", beginDate, rs.Fields("ScanTime"))) = arr(DateDiff("d", beginDate, rs.Fields("ScanTime"))) + 1
End If
rs.movenext
loop
rs.close
The line the error happens on is hash.Item(rs.Fields("ScanTime")).Item(arr(entry)) = hashHelp
I've checked all the other variable and they are being created and used just fine.

Related

Format Function Causing Undefined Variable Error in VBA for Task Scheduling

I am new to the forum but an active searcher and reader of this site for coding solutions.
I am enclosing some code that is part of a task i have scheduled which will open a file, refresh the data (line removed), and save it with a time stamp.
Option Explicit
Dim Xlapp, Xlbook,wbnam,ext,dt
Set Xlapp = CreateObject("Excel.Application")
xlapp.visible = TRUE
Set XlBook = xlapp.Workbooks.Open("C:\Users\newtonm\Box Sync\Matthew.Newton\Campaign Deliverables\Donor Dev\Weekly 10k\WklyTest.xlsx")
wbnam = "C:\Users\newtonm\Box Sync\Matthew.Newton\Campaign Deliverables\Donor Dev\weekly 10k\wklytest"
dt = format(date,"yyyy_mm_dd")
ext = ".xlsx"
xlbook.SavecopyAs wbnam&dt&ext
xlbook.Close false
xlapp.quit
set xlbook = Nothing
set xlapp = Nothing
When I execute the code - I am getting the following error.
I am presuming that 1 of 2 things is going on
1) The syntax of the Format Function is awry or.
2) Creating the Dim for DT is missing something.
Any help for this would be quitre helpful as i have been spinning my wheels for a bit on this.

Unspecified error while executing sql query vba on Oracle database

I want to import data from Oracle database to Excel using VBA. I've tried several options I found in here or in the official manual but none of them seem to work for me - I always get the same unspecified runtime error on line with
rs.Open strSQL1, con
or
Set rs = con.Execute(strSQL1)
depending on which one of these two methods I use obviously. Here is the whole code:
Sub data_distribution()
'Setting up the database connection
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSQL1, strInput, strCon As String
Set con = New ADODB.Connection
Set rs = New ADODB.Recordset
strCon = "Driver={Microsoft ODBC for Oracle}; " & _
"CONNECTSTRING=(DESCRIPTION=" & _
"(ADDRESS=(PROTOCOL=TCP)" & _
"(HOST=XXX)(PORT=XXX))" & _
"(CONNECT_DATA=(SERVICE_NAME=XXX))); uid=XXX; pwd=XXX;"
'--- Open the above connection string.
con.ConnectionString = strCon
con.Open
'con.Open strCon
'--- Now connection is open and you can use queries to execute them.
'--- It will be open till you close the connection
'Definition of parameter
strInput = InputBox("Insert car_id")
strSQL1 = "select * from car where car_id = " & strInput & ""
'Executing the query
'rs.activeconnection = con
'rs.Open strSQL1, con
Set rs = con.Execute(strSQL1)
rs.Open strSQL1, con
Worksheets("Data").Range("A2").CopyFromRecordset rs
'Closing connection
rs.Close
con.Close
Set con = Nothing
Set rs = Nothing
I was thinking it might be an issue of connecting to the database but if I import/query data manual, it works just fine. For example using this manual
http://blog.mclaughlinsoftware.com/microsoft-excel/how-to-query-oracle-from-excel-2007/
I had to download and configure ODAC for Windows from Oracle site to make it work. I use tsnames.ora to set the path. Wasn't sure if I configured it right but it works so I guess there isn't a problem with the connection in vba either, or is it? (The variables are, of course, set to real values, not "XXX")
The query itself is correct and returns valid results from the database. Libraries necessary to use ADOBD are linked as well. (Microsoft ActiveX Data Objects 2.0 Library)
There is an existing question with the same error but it's unresolved:
Unspecified run time error while executing vba script
I'm guessing it's station/interface specific (I use Excel 2010, SQL developer).
Even though it's been some time I asked the question, here, it's still unresolved so I will answer myself.
The problem was in the car table where one of the attributes was type CLOB (CHARACTER LARGE OBJECT) with lenght over 2000 characters. Excel was unable to cope with that type and the query caused the unspecified error. If I listed all attributes but this one, it all went well.

VB 2010 retrieve image

Good day sirs. I'm trying to retrieve a photo from my access database then load it in a PictureBox but I have this kind of problem which I can't resolve.
I have seen questions similar to mine but I can't understand the solutions given by others as I'm just a newbie. Will someone please help me correct my codes for retrieving image file from access database. Thanks
I'm using access database and Visual Basic 2010.
Here's the code:
Dim arrImage() As Byte
Dim myMS As New IO.MemoryStream
Dim da As New OleDb.OleDbDataAdapter("SELECT *
FROM tblEmp
WHERE EmployeeID= '"
& Me.txtID.Text
& "'", con)
Dim dt As New DataTable
da.Fill(dt)
If dt.Rows.Count > 0 Then
If Not IsDBNull(dt.Rows(0).Item("Picture")) Then
arrImage = dt.Rows(0).Item("Picture")
For Each ar As Byte In arrImage
myMS.WriteByte(ar)
Next
'
inFrm.PictureBox1.Image = Image.FromStream(myMS)
End If
End If
I'm getting a "Parameter is not valid" error from the line
inFrm.PictureBox1.Image = Image.FromStream(myMS)
try replacing the line of code with this
inFrm.PictureBox1.PictureData = myMS.Read

Crystal Reports TestConnection Fails

I have a Crystal Reports app that I am loading through VS2010. I have the CR Runtime 13.0.2 loaded on my machine. When I run the app using debug, it works fine. (Great in fact.) But when I install the application that is built (even on the VERY same dev machine.) the TestConnection line comes back false, which indicates to me that it's not connecting properly to my database.
If I don't put this code in there, the app prompts for login credentials at THIS line:
Me.CrystalReportViewer1.ReportSource = reportDocument1
But the DB Name and Server Name are incorrect and grayed out, and anything that I put in UserName and PW doesn't work.
I've searched google and tried any number of "fixes" and NOTHING gets it to work.
I also used database expert to "update" my datasource, and ran a "verify database" from design mode and still the same thing happens.
Here is my code:
Private Function ConnectReport(sDatabaseFile As String, _serverName As String, ReportDocument1 As ReportDocument)
ReportDocument1.SetDatabaseLogon("sa", "sqlAdmin2008", _serverName, sDatabaseFile, True)
For x As Integer = 0 To ReportDocument1.DataSourceConnections.Count - 1
ReportDocument1.DataSourceConnections(x).SetConnection(_serverName, sDatabaseFile, "sa", "sqlAdmin2008")
Next
For Each cTable As Table In ReportDocument1.Database.Tables
If cTable.Name <> "Command" Then
SetTableConnectionInfo(cTable, sDatabaseFile, _serverName)
End If
Next
For Each obj As ReportObject In ReportDocument1.ReportDefinition.ReportObjects
If obj.Kind = ReportObjectKind.SubreportObject Then
Dim subReport As SubreportObject = CType(obj, SubreportObject)
Dim subReportDocument As ReportDocument = ReportDocument1.OpenSubreport(subReport.SubreportName)
ConnectReport(sDatabaseFile, _serverName, subReportDocument)
End If
Next
End Function
Private Function SetTableConnectionInfo(cTable As Table, sDatabaseFile As String, _serverName As String)
Dim logonInfo As TableLogOnInfo = cTable.LogOnInfo
Dim connInfo As ConnectionInfo = New ConnectionInfo()
connInfo.DatabaseName = sDatabaseFile
connInfo.ServerName = _serverName
connInfo.UserID = "sa"
connInfo.Password = "sqlAdmin2008"
'connInfo.Type = ConnectionInfoType.SQL
logonInfo.ConnectionInfo = connInfo
cTable.ApplyLogOnInfo(logonInfo)
If cTable.TestConnectivity = False Then
Throw New ApplicationException("Cannot connect Crystal Reports to Database.")
End If
cTable.Location = sDatabaseFile & "." & "dbo" & "." & cTable.Location
End Function
It would seem to me that you need to pass the table in as a reference like this.
Private Function SetTableConnectionInfo(ref cTable As Table, sDatabaseFile As String, _serverName As String)

Crystal Reports in VB6 shows up empty for first run

So I'm having a problem with Crystal Reports where the first time I try to run the report, the report shows up empty. The report shows up with the various separators, lines, boxes, etc., but no data to fill in the report. I'm using Visual Basic 6 for the coding. I'm using a lot of inherited code and the code that handles the actual Crystal Reports is a file that is used for other reports and it works fine. So I'm sure the problem is from what I've done where I'm messing something up.
Here is the code I have so far:
Dim rs As ADODB.Recordset
Dim strRptFilePathTemp As String
Dim strRptFileName As String
Dim cSql As String
cSql = "SELECT * FROM TABLE1"
Set rs = DbConn.runStatement(cSql, "rs call", , , , , , , , , , True) 'gets a recordset based on the sql statement above
On Error GoTo ErrHandler
strRptFileName = "ReportName.rpt"
strRptFilePathTemp = App.Path
Screen.MousePointer = vbHourglass
Set frmcrystalreport.ReportRS = rs
DoEvents
frmcrystalreport.reportfile = strRptFilePathTemp & strRptFileName
frmcrystalreport.ReportTitle = _
frmCrystalReportsMainForm.GetRptTitle1("ReportTitle, ") & vbCrLf
gblStrReportFileNameLastRun = frmcrystalreport.reportfile
Screen.MousePointer = vbDefault
DoEvents
frmcrystalreport.Show vbModal
If Not frmcrystalreport.ReportRS Is Nothing Then
frmcrystalreport.ReportRS.Close
Set frmcrystalreport.ReportRS = Nothing
End If
Exit Sub
End If
End Sub
I've tried playing around with the DoEvents function to see if that can help but haven't had much luck with it. Everything works fine after that initial failed attempt at running the report. As long as I don't exit the program, it will print out a report with the valid data once I get passed that blank report. Thanks for any help you guys can give me.
Hmmm, it has been a while since I used VB6 and CR but I sort of remember that your need to discard the saved data before setting the viewers report source
Report.DiscardSavedData
CRViewer1.ReportSource = Report
Just figured out the problem after stumbling upon something in Crystal Reports. I had to turn off the save data with report feature in the report file under the File menu.

Resources