Microsoft VBScript runtime error '800a01a8' : object required - vbscript

Hi i have an ASP page that call function with 2 parameters
when i call the function from the asp page i am getting this error
Microsoft VBScript runtime error '800a01a8'
Object required: 'AllPerInfo4xfm(...)'
my code is
set GetAllInv = new GetFunction
set MyOrsk = GetAllInv.AllPerInfo4xfm(ssgr,nat)
my function is
Public Function AllPerInfo4xfm(ssgr,nat)
dim sdir,sdir2,ssec,tlen,ssec2
tlen=len(ssgr)
sql ="Select * from Personal"
myors2.Open SQl,oConn,1,1
set Allperinfo4xf = myors2
end function
did i miss something
please advice

Assuming that AllPerInfo4xfm() does not return an object, loose the Set in
set MyOrsk = GetAllInv.AllPerInfo4xfm(ssgr,nat)
=>
MyOrsk = GetAllInv.AllPerInfo4xfm(ssgr,nat)
Update wrt comment:
If AllPerInfo4xfm() should return a recordset, make sure the function contains a line
Set AllPerInfo4xfm = objRecordset
(replace objRecordset with your variable name; now, of course, the Set in the assignment to MyOrsk is needed)
Update wrt OT's revision:
Given the revised code, both GetAllInv and myors2 should be checked. Are they valid objects when the line is executed?
cf. food for thought

Related

Run-time error '91' when adding data to a record set

I want to insert some information into a database in VB6, but I get runtime error '91'.
My code:
Private sub btn_click()
Fname = txtFname.text
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("Fname") = Fname
Adodc1.Recordset.Update
End sub
The debuger shows error on: Adodc.Recordset.AddNew
You haven't posted the rest of the code as to where the Adhoc1 variable is created etc...
This post suggests that the RecordSet has not been initialized prior to working with it, but it's hard to be more specific without the code.
Runtime error '91' is Object variable or With block variable not set, which is a slightly confusing way to say that your variable contains Nothing.
You either forgot to initialise the Adodc1 properly, or, and this is more likely, you need to initialise Adodc1.RecordSet to something useful (like a Set Adodc1.RecordSet = New RecordSet or related) before you can use it.
By the way you posted the code, I believe that you will populate a Recordset to insert into the database. Try as follows:
sub btn_click()
dim Adodc1 as adodb.recordset
set Adodc1 = new adodb.recordset
Fname = txtFname.text
Rs.Fields.Append "Fname", adVarChar, 20 'adVarChar = text, followed by the amount of characters
Adodc1.open()
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("Fname") = Fname
Adodc1.Recordset.Update
End sub

VBScript Object Required When Trying to set DateTime

I am new to VBScript and can't figure out why I'm getting an Object Required error with my code. It's very simple right now, I've just begun it:
<%
set fs=Server.CreateObject("Scripting.FileSystemObject")
Dim dateandtime
On Error Resume Next
set dateandtime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
If Err <> 0 Then
' File operation(s) failed, handle the error
response.write(Err.Description)
End If
%>
Why am I not able to set the DateTime? I've set the FileSystemObject for use later in the code FYI. I'm just putting it all in here so you see exactly what I have. I figure it's a simple syntax thing but I can't seem to find the answer anywhere. Thanks for your help!
The first mistake is to use Set when assigning a non-object to a variable. The last entry in the 'Related' list “Object required” when using Set in an assignment deals with it.
>> Set dt = "a string"
>>
Error Number: 424
Error Description: Object required [because Set wants an object to assign]
No Set, no problem:
>> dt = "a string"
>> WScript.Echo dt
>>
a string
Removing the Set will reveal the next problem: Unless you defined a suitable class and an instance named 'DateTime' of your own, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") will fail with the same error 424.
>> dt = Nix.Now.ToString("")
>>
Error Number: 424
Error Description: Object required [to use its .Now member]
Do a search here for ways to format a date in VBScript. (First hit for "[vbscript] format date": date format in VBS)
The () in the .Write call should be removed; they are not parameter list (), but 'pass me per value' (). See this answer and follow the link to Eric Lippert's article.
What about crear your code and just do this?
<%
dateandtime = now()
response.write dateandtime
%>
To use setyou need a Object.

Forms(frmName) NOT WORKING

I am trying to use a string variable instead of hardcoding the forms name as below.
FrmMainControl.Controls
but want to use this.
Forms("FrmMainControl").Controls
However, i get the error Sub or Function not defined. Please help. This is in VBA btw.
Assuming the form is loaded you can search the UserForms collection;
Dim form As UserForm: Set form = getInstanceOfLoadedUfrm("frmMainControl")
If Not form Is Nothing Then
MsgBox form.Controls.Count
Else
'//load
Set form = UserForms.Add("frmMainControl")
MsgBox form.Controls.Count
End If
Function getInstanceOfLoadedUfrm(name As String) As UserForm
name = UCase$(name)
For Each form In UserForms
If (Ucase$(form.name) = name) Then
Set getInstanceOfLoadedUfrm = form
End If
Next
End Function

ArcPad - VBscript - Autopopulate attributes

I am using the following script to grab parcel and address information from one layer to fill the attribute table of a newly created feature.
There is no returned error, but the problem I am having is that there seems to be the wrong information stuck in the memory of recordselect function. No matter where I place a point it gives the same parcel # and address. Or maybe it isn’t actually be performing the IF function properly.
Sub Address
Dim rsCurrentXY
Set rsCurrentXY = Map.Layers("Violations").records
rsCurrentXY.movelast
Dim objXYShape
Set objXYShape = rsCurrentXY.Fields.Shape
Dim pControls
Set pControls= Application.Map.selectionlayer.Forms("EDITFORM").Pages(“PAGE1”).Controls
Dim rsGrid
' Find corresponding map page to the valve point
Set rsGrid = Map.Layers("ACPA_parcels").records
rsGrid.movefirst
Do While Not rsGrid.eof
If rsGrid.fields.shape.Ispointin(objXYShape) Then
pControls("txtAddress").value = rsGrid.Fields("ADD1").Value
Exit Do
End If
rsGrid.Movenext
Loop
' Clean Up
Set rsCurrentXY = Nothing
Set objXYShape = Nothing
Set rsGrid = Nothing
End Sub
(I have another subroutine called "PIN" that would do the exact same thing.)
I have them called when their respective edit boxes in the custom form are activated by the inspector.
Thanks for the help,
Robert
Accessing the EDITFORM via Application.Map.selectionlayer.Forms("EDITFORM") will be problematic. Whenever working with controls on an EDITFORM you should using ThisEvent.Object to discover all your objects. For example, if your event handler is Page_OnLoad then ThisEvent.Object will refer to your current page. You should have code like this:
Dim pPage1
Set pPage1 = ThisEvent.Object
Dim pControls
Set pControls = pPage1.Controls

VB6 execution with database is different when stepping through vs running

I've come across a weird scenario with the following code in a vb6 app:
Private database As dao.Database
Set database = openDaoDatabase([some valid database location], False)
createDBField database, "Table", "FirstRow", dao.dbInteger, 0, "0"
Public Sub createDBField(targetDB As dao.Database, strTable As String, strField As String, dbType As dao.DataTypeEnum, Size As Integer, strDefValue As String)
Dim td As dao.TableDef
Dim fld As dao.field
Set td = targetDB.TableDefs(strTable)
Set fld = td.CreateField(strField, dbType, 0)
If dbType = dao.DataTypeEnum.dbText Or dbType = dao.DataTypeEnum.dbMemo Then fld.AllowZeroLength = True
If strDefValue <> "" Then fld.DefaultValue = strDefValue
td.Fields.Append fld
Set td = Nothing
Set fld = Nothing
End Sub
When I step through, everything works and the new field is added to the database. However, when I simply run the application, the database becomes corrupted due to 'inconsistency'. I added some error handling and now get the error: "Unrecognized database format: [path]".
After searching the Microsoft database, I found a solution: http://support.microsoft.com/kb/238401. I'm using the Microsoft.Jet.OLEDB.4.0 provider, have SP6 installed and have a reference to the Microsoft DAO 3.6 Object Library, but it's still not working!
Any thoughts?
Update:
td.Fields.Append fld is the culprit. After removing all silent error handling, I was able to catch an error: "Run-time error 3343 Unrecognized Database Format". For some reason, I can just step over it though.
I suspect your problem is happening because of the AllowZeroLength property. I suspect the field should be added to the fields collection and the AllowZeroLength property updated.
After
td.Fields.Append fld
put something like the following:
Set tdfField = tabledef.Fields(strField)
Set prp = tdfField.CreateProperty("AllowZeroLength", dbboolean, True)
tdfField.Properties.Append prp
Note the above is aircode and not tested.
That said, it doesn't make a lot of sense to me for a text or MEMO field's AllowZeroLength property to default to True. After all, the front end user can't really visually distinguish between the NULL value and a zero length string value.
I don't see a call to database.close that might be the cause. If your VB app terminates abruptly that might leave the DB in an inconsistent state.
Which line is the error occurring on? Usually when I run into VB errors like this they are timing related. Stepping through gives enough time for something to finish processing. Try adding some sleep commands before the statement that is causing the error.

Resources