Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Runtime Error 91 Object Variable Or With Block Variable Not Set


Hi all,

I need help on this badly,
As title i run into this error (Runtime error 91 Object variable or With Block variable not set) after I package my program and install it on my local computer(WinXP SP2).
I ensure all my objects had been set and option explicit declare on every page of the code as from what I search from this forum.
But this error only came when I wanted to execute the program after installation.
I got no idea where to track the code where throws the error but during compiling all are fine.

Many Thks.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Runtime Error 91 Object Variable Or With Block Variable Not Set
Hi,

when I run my .exe I have this run time error 91 Object variable or with block variable not set when I create my textfile

_---------------------------------------------------_
Dim objFSO As FileSystemObject
Dim objTextFile As TextStream
Dim strFileName As String
Dim strRead As String

Public Sub WriteToFile()

strFileName = "C: ext.txt"
Set objTextFile = objFSO.CreateTextFile(strFileName,True)<---------------------------------rutime error 91
objTextFile.WriteLine ("I am writing to the text to the file.")
objTextFile.WriteLine ("")
objTextFile.WriteLine ("I am writing to the text to the file.")

End Sub
_----------------------------------------------------_

thanks

David

Runtime Error 91. Object Variable Or With Block Variable Not Set
This error message is fast becoming the bane of my life! More irritatingly, I've no idea what it actually means, either. Can someone explain (in laymans terms, please ) what sort of thing causes it?

In the instant case, I'm just trying to read an access DB; I need to get a patient's last appointment from it to show up on a screen before the new one is entered. I'm getting the 91 error when I try and move to the last record in the recordset.

I'm referrencing an ADODC that (as far as I can see) looks correctly set up. I am doing so, however, in the form_load() routine, and one thing that occured to me was that maybe the ADODC doesn't "come into existence" until the form has actually been drawn? If this is the case, I can understand why it wouldn't work, as there'd be no connection yet between the program and the DB.

The complete routine is:





Code:
Sub Form_Load()

'First up, add units 1-10 into both the admin and treatment combi box
Dim AddUnits As Integer
For AddUnits = 1 To 10 Step 1
cmbTrtUnits.AddItem AddUnits%
cmbAdminUnits.AddItem AddUnits%
Next

' Now add the Day/Night options in
cmbDayNight.AddItem "D"
cmbDayNight.AddItem "N"

'And the workshop/clinc
cmbClinWShop.AddItem "W"
cmbClinWShop.AddItem "C"

'And finally, pull the OTs from the parmfile.
Dim conParmfile As ADODB.Connection
Dim dtaParmfile As ADODB.Recordset
Set conParmfile = New ADODB.Connection
conParmfile.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=databasesparmfile.mdb;"
'conParmfile.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=databasesparmfile.mdb;"
conParmfile.Open
Dim RecordType As Long
RecordType = 20
Set dtaParmfile = conParmfile.Execute("SELECT * FROM parmfile WHERE recordtype = " & RecordType)
dtaParmfile.MoveFirst

' Loop from the start of the file through to EOF and add the names provided
' into the OT combibox.
Do Until dtaParmfile.EOF
cmbAttendingOT.AddItem (dtaParmfile.Fields.Item("Data").Value)
dtaParmfile.MoveNext
Loop

' The next type of records to load into the combi-box are the treatment.
RecordType = 30
Set dtaParmfile = conParmfile.Execute("SELECT * FROM parmfile WHERE recordtype = " & RecordType)
dtaParmfile.MoveFirst

' Loop from the start of the file through to EOF and add the treatments
' provided in the parmfile into the treatment combibox.
Do Until dtaParmfile.EOF
cmbTreatment.AddItem (dtaParmfile.Fields.Item("Data").Value)
dtaParmfile.MoveNext
Loop

' ...and close the Parmfile off.
conParmfile.Close

' put the name, OT number and NHS numbers into the label fields
lblNHSNumber = frmAddress.txtField(9).Text
lblName = frmAddress.txtField(1).Text & " " & frmAddress.txtField(0).Text
lblOTN.Caption = frmAddress.txtField(24).Text

' Disable the Confirm Buttton
cmdConfirm.Enabled = False

' And hide the new appt text boxes
showNewApptFields False

With Adodc1.Recordset
.MoveLast (<- this is the line it highlights when it falls over)
Do Until lblOTN.Caption = .Fields(1).Value Or .BOF
.MovePrevious
Loop

If .BOF = True Then
MsgBox ("There is no previous appointment on record for this patient")
Exit Sub
End If

lblOldDate = .Fields(2).Value
lblOldAdminUnits = .Fields(4).Value
lblOldTrtUnits = .Fields(3).Value
lblOldDayNight = .Fields(5).Value
lblOldTreatment = .Fields(6).Value
lblOldClinWShop = .Fields(7).Value
lblOldAttendingOT = .Fields(8).Value
End With

' Preparations for adding in the new record are done, exit sub.

End Sub

What's really bugging me is that it worked fine before; I changed a couple of bits (not these bits, however!), and now it doesn't!

Any help will be very, very gratefully received!

Runtime Error 91: Object Variable Or With Block Varialbe Not Set
Hello,
I have a program that dynamicly creates forms at runtime. I use an array called Board(). After I

Code:
'set Board(t) = new frmDAQ'

I then

Code:
'call board(t).setup(MyID,MyType,MyMode)'


setup() then changes the form size, eventually it will also move controles around, etc.

Setup also relies on a few functions, BoardID, BoardType, and CurrentMode to read and change a few variables.

Later in my program I need to read the BoardID. When I

Code:
'msgbox board(1).BOARDID'

I get error 91.

I don't understand the error message...


This is part of my serial isr...

Code:
Case 24 'sound off
BoardCount = BoardCount + 1
ReDim Board(BoardCount)

Select Case Asc(Buffer(5))
Case 1 'its a DAQ
ItemText = Asc(Buffer(4)) & " - DAQ"
Set Board(BoardCount) = New frmDAQ
Case 2 'its a Servo
ItemText = Asc(Buffer(4)) & " - Servo"
Set Board(BoardCount) = New frmServo
Case 3 'its a Nunchuck
ItemText = Asc(Buffer(4)) & " - Nunchuck"
Set Board(BoardCount) = New frmNunchuck
End Select
lstBoardList.AddItem ItemText


If I put msgbox BoardCount in the serial isr. I see the expected values. If the exact same line is anywhere else it gives me error 91.

It is almost 3am where I'm at..I am having problems reading...

Runtime Error '91' Object Or With Block Variable Not Set For WebBrowser Control
Hi Scott,

I want to get the login & Password text automatically/programatically entered when i browse the website http://www.rediffmail.com. For this I am writing the code given below

Private Sub Form_Load()
WebBrowser1.Navigate WebBrowser1.Navigate
"http://www.rediffmail.com"
End Sub

Private Sub Command1_Click()
WebBrowser1.Document.Forms("0").elements("login").V alue = "NAME"
WebBrowser1.Document.Forms("1").elements("passwd"). Value =
"password"
End Sub

First line of the command1_click works but for Second line I am getting the runtime error '91' as mentioned above.
Please give me the solution for this.

Also, this is for the URL www.rediffmail.com, the same runtime error i am getting if i am using the URL starting with "https://www. so on".
Please let us know the feedback.

Subhash

91:Object Variable Or With Block Variable Not Set(MDI Form Close Error)
When i close the password form above the MDI form,then i click the menu "password" again to enable it to open the password form again,but it pop up the error,"91:Object variable or With block variable not set".Here is my coding.Anyone can let me know where is my error?


VB Code:
Private Sub mnuChange_Click() On Error GoTo exithandler     Call Unload(ActiveForm)    Call Load(frmPwd)    frmPwd.Show    exithandler:         If Err Then        Call MsgBox(Err.Number & " : " & Err.Description)        Err.Clear    End If

Run Time Error 91 - Object Variable Or With Block Variable Not Set
Hi,

when I run my .exe I have this run time error 91 Object variable or with block variable not set ... i'm using a VB6 and this code was inseide in Module, the two function Criar_arquivo and TextoFixo was called inside of command button....

==================================
module
=====================================
Global word1 As Object
Function Criar_arquivo() As Integer

Dim word1 As Object
Set word1 = GetObject("", "word.application.8")
Set word1 = CreateObject("Word.Application.8")
word1.Documents.Add

End Function

Function TextoFixo() As Integer

With word1.Selection <---------------- error
.TypeText (Frame1.Caption)
.TypeParagraph
.HomeKey Unit = wdLine, Extend = wdExtend
With word1.Selection.Font
.Name = "Times New Roman"
.Size = 14
.Bold = True
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.Strikethrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = True
.Color = wdColorAutomatic
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0
.Scaling = 100
.Position = 0
.Kerning = 0
.Animation = wdAnimationNone
End With
End With

word1.Visible = True

With word1.Selection
.TypeText (Text1.Text)
.TypeParagraph
.HomeKey Unit = wdLine, Extend = wdExtend
With word1.Selection.Font
.Name = "Times New Roman"
.Size = 14
.Bold = True
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.Strikethrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = False
.Color = wdColorAutomatic
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0
.Scaling = 100
.Position = 0
.Kerning = 0
.Animation = wdAnimationNone
End With
End With
word1.Visible = True

End Function
==========================================

==================================
button
=====================================
Private Sub Command4_Click()


If Frame10.Enabled = True Then
Command4.Enabled = True

Criar_arquivo
TextoFixo
.
.
.
.
.
end sub



thanks

Rick

Run-time Error '91': Object Variable Or With Block Variable Not Set
Hello,

One of our users has a particular problem wit MS Excel. When she has a standard worksheet opened and want to close excel, a box with the typically VB questions "End" or "Debug" appeares. When the user clicks on End the message "Run-time error '91': Object variable or With block variable not set" appeares.

What could there be wrong? Can I resolve this bij resetting the users profile or is it caused by the specified excelsheet?

THX in advance!

Stoffel

Help With This Error: Object Variable Orwith Block Variable Not Set
it says, object variable or with block variable not set

i'm working here for an update to a mother table and child table

here's my code:



Code:
Private Function CalcUpdate()

Dim sUpdSql As String
`
sUpdSql = "UPDATE tblPayrollInfo SET SalaryLoan = Text1(0).Text,PolicyLoan=PolicyLoan = Text1(3).Text," _
& "Premium = Text1(6).Text, SalaryLoan_Pay = Text1(19).Text, PolicyLoan_Pay = Text1(20).Text," _
& "SalPayableIn =Text1(1).Text, PolPayableIn = Text1(4).Text, PrePayableIn = Text1(7).Text," _
& "IRateSal = Text1(2).Text, IRatePol = Text1(5).Text, IRatePre = Text1(8).Text," _
& "PhilHealthMed = Text1(9).Text, GSIS =- Text1(10).Text,OptionalPrem = Text1(11).Text, ODed1 = Text1(12).Text," _
& "ODed2 = Text1(13).Text, ODed3= Text1(14).Text, Desc1= Text2(0).Text,Desc2 = Text2(1).Text," _
& "Desc3=Text2(2).Text,Tax = Text1.Text, RATA = Text1(16).Text, ACA = Text1(17).Text, PERA = Text1(18).Text," _
& "Allowance =Text1(22).Text, GrossPay = Text1(23).Text, Deduction=Text1(24).Text, NetIncome=Text1(25).Text WHERE EmpInfo = " & cboEmpId.Text & " "

End Function




Code:
With adoEmp
.MoveLast
.AddNew
CalcUpdate
End With

adoEmp.Requery
please help out. tnx. it's really important

Run-time Error 91. Object Variable Or With Block Variable Not Set
Hi everybody,
The title of this message is nithing but the error message am having anytime I run my apllications on another computer.I mean different from the the one on which I developed it with.the applications are databse oriented and I do connect either using ODBC driver or OLE Jet 4.0.all the applications run perfectly on my system but I couldn't run them on other systems.where do you think the problem is (my system or the others) and what precisely can it be?thanks for your Removed By Mod

Run-time Error '91': Object Variable Or With Block Variable Not Set
Hi,

I developed a small sized application with database using VB 6.0 Enterprise SP-5 on a Win XP Pro box. The application runs just fine on this box. Later I created an installer using Inno-setup and got it installed on Win ME, I got above mentioned error when I open a form that was created using "Data Form Wizard" having connected to database using DSN and connection method being ADO-Control.

As per my investigation, the problem is that the application expects me to declare the "datPrimaryRS" which is the name of the ADODC control given by the wizard. Now I have no idea how can I declare an activex control?

I will appreciate if anybody can help me out on this issue.

PJ

Run Time Error 91 Object Variable Or With Block Variable Not Set
i have one form that creates a sql statement, and loads the results form, that uses the sql statement to search and display results.

the sql statement variable is defined in the first form as a public variable and the second form access it in my code like this:


VB Code:
with form1       ...findfirst .sqlvariableend with


but when it runs it comes up with the error in the title of this post??

can anyone see the problem???

GTJ

Run-Time Error 91 : Object Variable Or With Block Variable Not Set
Hi,
I've compiled an executable file which runs perfectly fine on the computer i initially created the program on but once i attempt to run the .exe on another computer there is no data in the datagrid and also when i attempt to scroll through the records i receive the error "Run-Time Error 91 : object variable or With block variable not set." Any ideas what the problem might be and how to solve it, much appreciated.
Thanks.

Run Time Error 91: Object Variable Or With Block Variable Not Set
I am trying to run this code and received the said error message on the second loop of the program on this specific line:

" ActiveWorkbook.SaveAs FileName:=Left(ActiveWorkbook.FullName, 20) & ".csv", FileFormat:=xlCSV, CreateBackup:=False "

circumstances: I am converting a multiple selected .xls file which i have chosen in a filelistbox into a .csv format
------------------------------------------------------------------------------------

Dim Exceltemp As Excel.Application
Dim I As Integer

Private Sub CmdConvert_Click()

For I = 0 To File1.ListCount - 1
MsgBox File1.List(I)
sChar = ""
If File1.Selected(I) Then
Set Exceltemp = New Excel.Application
If Right(Dir1.Path, 1) = "" Then
Exceltemp.Workbooks.Open File1.Path & File1.List(I)
Exceltemp.Visible = True
Set Exceltemp = Nothing
Else
Exceltemp.Workbooks.Open File1.Path & "" & File1.List(I)
Exceltemp.Visible = True
Set Exceltemp = Nothing
End If
frmConversion.Status1.Panels(1).Text = "Converting file into .CSV format...."
ActiveWorkbook.SaveAs FileName:=Left(ActiveWorkbook.FullName, 20) & ".csv", FileFormat:=xlCSV, CreateBackup:=False
ActiveWorkbook.Close
End If
Next
frmConversion.Status1.Panels(1).Text = "Excel File converted into .CSV format..."
End Sub


Thanks a lot

Object Variable Ot With Block Variable Not Set (run-time Error 91)
What is wrong with the following code? The debugger gives an error at the blue line.

Sub dateadj()

Dim x As Integer
Dim a As Date

For x = 1 To 429
Worksheets("sheet5").Select
Cells(1222 + x, 6).Select
a = Cells(1222 + x, 6).Value
Selection.Copy
Worksheets("aangepast").Select
Cells(1 + x, 1).Select
ActiveSheet.Paste


Worksheets("sheet5").Select
Columns("A:A").Select


Selection.Find(What:=a, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate


ActiveCell.Offset(0, 1).Select
ActiveCell.Offset(0, 1).Copy
Worksheets("aangepast").Select
Cells(1 + x, 2).Select
ActiveSheet.Paste

Next x


End Sub

Run-time Error 91 Object Variable Or With Block Variable Not Set
Hi all,

I'm getting the following error message when I tried to use stored procedure in VB.6. Can anyone help me?

Run-time error 91 object variable or with block variable not set


Here is my code:

Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim cmd As ADODB.Command
Dim strconn As String
Dim MyID As Integer

Private Sub Form_Load()

strconn = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=ma;Password=p2008;Initial Catalog=T_DB;Data Source=NSERVERDEV"
con.Open strconn
conn_info
End Sub

Private Sub conn_info()
MyID = InputBox("Enter a Report ID")
Set cmd = New ADODB.Command
cmd.ActiveConnection = con
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "Update_Job_Status"

cmd.Parameters.Append cmd.CreateParameter("JobID", adNumeric, adParamInput, 5, MyID)
Set rs = cmd.Execute

If Not rs.EOF Then
lblId.Caption = rs.Fields(0)
lblRun.Caption = rs.Fields(20)
End If

Set cmd.ActiveConnection = Nothing

End Sub

Thanks,
A
 

URGENT!!!! Error 91- Object Variable Or With Block Variable Not Set
Hi ppl.

This is an URGENT request. I made a program involving some ADODC and the .exe worked pretty fine in my computer (VB6, WinME), but when I copied it into a WinXP w/o VB computer, it asked me for some dll's and ocx. So I downloaded them and... The program ran, but NO RECORDS ARE SHOWN!!!! As if there is no link to the DB. Also, when I try to push any CmndBtn, the

Error 91 - Object variable or With block variable not set

is shown, and the program closes.

I suppose both problems are linked AND have to do with the ADODC, but I've no idea what to do. The program has no apparent errors (although I know it can be simplified) and the Err91 Msgbox appeared only when trying to execute the compiled file.

Any suggestions appreciated FAST!
PD.- The code is somewhat extense. If u need it to be shown, pls specify the part you want.

Thanks in advance,

UVMVB

Object Variable Or With Block Variable Not Set (Error 91)
Private sub form_load
'yada-yada
cborecent_click
end sub

Private Sub cboRecent_click()
If InStr(1, cboRecent.Text, "-") Then
strFindID = Left(cboRecent.Text, InStr(1, cboRecent.Text, "-") - 1)
ElseIf InStr(1, cboRecent.List(0), "-") Then
strFindID = Left(cboRecent.List(0), InStr(1, cboRecent.List(0), "-") - 1)
Else
strFindID = ""
End If
cmdFindID_click
End Sub

Private Sub cmdFindID_click()
Dim cnt As Integer
Dim swapstring As String
Dim swapindex As Integer
If strFindID = "" Then
strFindID = InputBox("Please enter the Request ID to locate.")
bkmk = rs.Bookmark
Else
swapstring = "GO"
End If
'Debug.Print strFindID **** strFindID is set correctly
'Exit Sub
Data1.Recordset.FindFirst "[Request_ID] like " & Chr(34) & strFindID & "-*" & Chr(34)
this is where it blows up with data1.recordset.findfirst.
If I remove the cboRecent_click from Load_form above everything
works as it should even data1.recordset.findfirst. Can I not execute this from Load_Form? How should I approach this?

[HELP]Error 91: Object Variable Or With Block Variable Not Set
hello to all its nice to meet yah guys!

can any pls help me about this code i tried to create an login that check the username and password in the the access database and if the user exist then the user will able to enter into the system.

everytime i run the system it give me an error of

Error 91: Object variable or With block variable not set


my database name was momsdb.mdf and it is inside folder "database"

this inside my module file

Code:
Public rs As New ADODB.Recordset
Public con As ADODB.Connection

Public Function connect()
On Error GoTo err
Set con = New ADODB.Connection
con = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "databasemomsdb.mdb;Persist Security Info=False"
con.Open
Exit Function
err:
MsgBox err.Description
End Function
my login form.


Code:
Public LogSuccess As Boolean

Private Sub cmdCancel_Click()
If MsgBox("Are you sure you want to quit the System?", vbYesNo) = vbYes Then End
LogSuccess = False
End Sub

Private Sub cmdClear_Click()
clear
txtUserName.SetFocus
End Sub

Private Sub cmdOK_Click()
On Error GoTo err
If txtUserName.Text = "" Then
MsgBox "Invalid Username!"
ElseIf txtPassword.Text = "" Then
MsgBox "Invalid Password!"
ElseIf txtUserName.Text = "" And txtPassword.Text = "" Then
MsgBox "Please don't leave field blank."
Else
LogSuccess = False
SQL = "SELECT * FROM tbllogin"
Set rs = con.Execute(SQL)
If rs.BOF = False Then
While Not rs.EOF
If txtUserName.Text = rs(0) And txtPassword.Text = rs(1) Then
username = rs(0)
LogSuccess = True

End If
rs.MoveNext
Wend
End If

If LogSuccess = True Then
Unload Me
Else
MsgBox ("Invalid username, try again!")
End If
err:
MsgBox err.Description & " " & err.Number
End If
End Sub

Private Function clear()
txtUserName.Text = ""
txtPassword.Text = ""
End Function

Error 91 Object Variable Or With Block Variable Not Set
Error 91 : object variable or with block variable not set

I only get this error at runtime when the application is compiled. But i cannot duplicate nor find this error anywhere when debugging in the development environment.

Error 91: Object Variable Or With Block Variable Not Set
Can anyone see what causes Error 91: Object variable or With block variable not set
I should add that this only happens when I have the bit of code that I have marked


Code:
Private Sub Form_Load()
Me.Visible = False
Dim x As Integer
Dim y As Integer
Dim rc As RECT
Dim ABD As APPBARDATA
Dim hWndAppBar As Long
ABD.cbSize = Len(ABD)
state = SHAppBarMessage(ABM_GETSTATE, ABD)
For position = ABE_LEFT To ABE_BOTTOM
ABD.uEdge = position
hWndAppBar = SHAppBarMessage(ABM_GETAUTOHIDEBAR, ABD)
If hWndAppBar > 0 Then
Select Case position
Case ABE_LEFT: position = 1
Case ABE_TOP: position = 2
Case ABE_RIGHT: position = 3
Case ABE_BOTTOM: position = 4
End Select
End If
Next

MakeWindowNotTop Me.hwnd
SHAppBarMessage ABM_GETTASKBARPOS, ABD
h = ABD.rc.Bottom - ABD.rc.Top
tb = ABD.rc.Bottom - ABD.rc.Top
h = h * 15
If position <> 4 And state <> 2 Then
h = 0
End If
x = Screen.Width
y = Screen.Height

Dim myProcesses As Integer
Dim proc As PROCESSENTRY32
Dim snap As Long
Dim exename As String
Dim shift_over As Integer
snap = CreateToolhelpSnapshot(TH32CS_SNAPall, 0)
proc.dwSize = Len(proc)
processLoop = ProcessFirst(snap, proc)
While processLoop <> 0
exename = proc.szExeFile
If InStr(exename, "desktalker.exe") Then
myProcesses = myProcesses + 1
End If
processLoop = ProcessNext(snap, proc)
Wend

shift_over = myProcesses * 3500
'from here
If shift_over > x Then
MsgBox "You have too many Desktalkers installed for your screen " & _
"width to accomodate. You may increase the number of " & _
"Desktalkers that can open by increasing your screen resolution. " & _
"Consult a technician for details and assistance.", _
vbInformation, "Demo Name"
End
End If
'to here. If this is taken out then no error
CloseHandle snap


frmMain.Left = (x - 3495) - (shift_over - 3500)
frmMain.Top = (y - 1050) - h
If IsConnectedToInternet() = False Then
tmrGetChunk.Enabled = False
WebBrowser1.Offline = True
Else:
WebBrowser1.Navigate "website address"
End If
new_state = state
new_position = position
new_tb = tb
Me.Visible = True
End Sub
Thanks
Robert

Object Variable Or With Block Variable Not Set (Error 91)
Hi all, can someone help me please.

I'm using Visual Basic for first time, and I try to set up a Macro in Excel:




Sub Name()
'
' Name Macro
' This Macro is searching for a Enquires Name
'

'
Sheets("Bookings").Select
Range("G24").Select

var1 = InputBox("Please enter the Family Name:", "Enguiries Name")

Range("A24:I50").Sort Key1:=Range("G25"), Order1:=xlAscending, Header:= xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal


If Cells.Find(What:=var1, After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase :=False, SearchFormat:=False).Activate Then
MsgBox "Enquiries Name was found", vbDefaultButton1, "Success..."

ElseIf var1 <> "" Then
MsgBox "Enquiries Name was not found", vbCritical, "Try Again..."

End If
End Sub

Each time, when I run it. It is working, if I put a value in, that is in my sheet. But when I try to put something, that is not there. I have not my ElseIf value but an.................................................................... .. Object variable or With block variable not set (Error 91)

I have no Idea why:-( Can u help me please.

Thanx

Have a nice Day

Object Variable Or With Block Variable Not Set (Error 91)?
hi i'm trying to get the firstname and lastname to show up on a html doc called certificate_cd.htm. there is a <h2 id="userName">&nbsp;</h2><p> reffering to the WebBrowser1.Document.All("userName").innerHTML
now if i have WebBrowser1.Document.All("userName").innerHTML uncommented, it gives me a run-time error of 91. but if i comment it out and have the msg boxes it does what i want. which is return the value of firstname and lastname. now, why am i getting that error when i try to set WebBrowser1.Document.All("userName").innerHTML= firstName & lastName? I've even tried to use cStr(firstName) & cStr(lastName).

help!

/a


Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
Dim currLocation As String
Dim userName
currLocation = WebBrowser1.LocationURL
If (MH_BaseFileName(URL) = "testyourself") Then
UpdateQuizPage
ElseIf (MH_BaseFileName(URL) = "introduction") Then
Dim newURL
newURL = Mid(URL, 158)

Dim newURLarray
newURLarray = Split(newURL, "&")
firstName = Mid(newURLarray(0), 7)
lastName = Mid(newURLarray(1), 6)

ElseIf (InStr(1, currLocation, "certificate_cd") > 0) Then

MsgBox firstName & " " & lastName & "hi"
'On Error Resume Next
MsgBox firstName & " " & lastName & "hi2"
WebBrowser1.Document.All("userName").innerHTML = CStr(firstName) & " " & CStr(lastName)
MsgBox firstName & " " & lastName & "hi3"
'WebBrowser1.Document.All("userName").scrollIntoView (True)
End If
End Sub

Object Variable Or With Block Variable Not Set (Error 91)
If Data2.Recordset.EOF = False Then
While Data2.Recordset.EOF = False
Data2.Recordset.Delete
Data2.Recordset.MoveNext
Wend
End If

come out this error :
Data2.Recordset.EOF = <Object variable or With block variable not set >

I just want to delete the data in my database.

Thanks for helping me!

Object Variable Or With Block Variable Not Set Error.
Hi

I was wondering if anyone can see where I have done wrong that it gives me error of object variable or with block variable not set error on :

Set RS = DB.OpenRecordset(SQL)

My whole code is :

Private Sub Command1_Click()
Dim SQL As String
Dim RS As Recordset
Dim DB As Database
Dim x As Long


If Option1.Value = True Then
x = 1
End If
If Option2.Value = True Then
x = 2
End If
SQL = "Insert Into User " & _
"(Name, Gender, Age, Course, Field, Email) " & _
"Values " & _
"('" & Trim(Text1.Text) & "', " & x & _
"'" & Trim(Text2.Text) & "', " & _
"'" & Trim(Text3.Text) & "', " & _
"'" & Trim(Text4.Text) & "', " & _
"'" & Trim(Text5.Text) & "' )"

Set RS = DB.OpenRecordset(SQL)

End Sub

Private Sub Form_Load()
Dim DB As Database
Open "c: est.txt" For Append As #1
Set DB = OpenDatabase(App.Path & "/db3.mdb")
End Sub

Private Sub Form_Unload(Cancel As Integer)

Set RS = Nothing
DB.Close
Set DB = Nothing
End Sub

Object Variable Or With Block Variable Not Set - Error
Hi friends,

Please guide me to solve this problem.


VB Code:
ers!c1s1 = rss1.Fields("c1s1")

Error #91 Object Variable Or With Block Variable Not Set
I'm running an access 2003 project and I'm trying to password protect one of my forms but I keep getting that error when I open the form. Once I click OK the form opens that I want to protect. I followed this to the "T". Here is the script I'm using.

1. Start Access and then open the sample database Northwind.mdb.
2. Press ALT+F11 to start the Microsoft Visual Basic editor.
3. On the Insert menu, click Module.
4. In the module sheet, type the following procedure:Public MyPassword

VB Code:
Public Function KeyCode(Password As String) As Long   ' This function will produce a unique key for the   ' string that is passed in as the Password.   Dim I As Integer   Dim Hold As Long    For I = 1 To Len(Password)      Select Case (Asc(Left(Password, 1)) * I) Mod 4      Case Is = 0         Hold = Hold + (Asc(Mid(Password, I, 1)) * I)      Case Is = 1         Hold = Hold - (Asc(Mid(Password, I, 1)) * I)      Case Is = 2         Hold = Hold + (Asc(Mid(Password, I, 1)) * _            (I - Asc(Mid(Password, I, 1))))      Case Is = 3         Hold = Hold - (Asc(Mid(Password, I, 1)) * _            (I + Len(Password)))   End Select   Next I   KeyCode = HoldEnd Function


5. Press ALT+F11 to return to Access.
6. In the Database window, under Objects, click Tables, and then click New.
7. In the New Table dialog box, double-click Design View.
8. Create a new table as follows: Table: tblPassword
---------------------------
Field Name: ObjectName
Data Type: Text
Field Size: 50
Field Name: KeyCode
Data Type: Text
Field Size: 25
Input Mask: Password

Table Properties: tblPassword
-----------------------------
PrimaryKey: ObjectName


9. Open the tblPassword table and then enter the following data: ObjectName: Orders
KeyCode: 2818


10. Create a new form in design view and save the form as frmPassword.
11. Add a single textbox to frmPassword called Text0, and a command button called CheckPassword.
12. Set the Input Mask property of Text0 to "PASSWORD" (minus the quotation marks).
13. Add the following code to the OnClick Event of the CheckPassword button and then save the form:
VB Code:
If IsNull(Forms!frmPassword!Text0.Value) Then                 MsgBox "You cannot enter a blank Password. Try again."                 Me!Text0.SetFocus            Else                 MyPassword = Me!Text0.Value                 DoCmd.Close acForm, "frmPassword"            End If


14. Open the Orders form in Design view.
15. If the property sheet is not visible, click Properties on the View menu.
16. Type the following event procedure in the module for the OnOpen property of the form:Private Sub Form_Open(Cancel as Integer)

VB Code:
Dim Hold As Variant   Dim tmpKey As Long   Dim I As Integer   Dim rs As DAO.Recordset   Dim db As DAO.Database    On Error GoTo Error_Handler   ' Prompt the user for the Password.   DoCmd.OpenForm "frmPassword", acNormal, , , , acDialog            Hold = MyPassword' Open the table that contains the password.   Set db = CurrentDb   Set rs = db.OpenRecordset("tblPassword", dbOpenTable)   rs.Index = "PrimaryKey"   rs.Seek "=", Me.Name   If rs.NoMatch Then      MsgBox "Sorry cannot find password information. Try Again"      Cancel = -1   Else      ' Test to see if the key generated matches the key in      ' the table; if there is not a match, stop the form      ' from opening.      If Not (rs![keycode] = KeyCode(Cstr(Hold))) Then         MsgBox "Sorry you entered the wrong password." & _            "Try again.", vbOKOnly, "Incorrect Password"         Cancel = -1      End If   End If   rs.Close   db.Close   Exit Sub Error_Handler:   MsgBox Err.Description, vbOKOnly, "Error #" & Err.Number   Exit Sub
End Sub

Object Variable Or Block Variable Not Set Error
Hello... I'm trying to write a simple program for a class to pull data from a table and write it to a random file.. or text file.. but i keep getting that stupid error message "Object Variable or Block Variable not set" Here is my Code..

VB Code:
Option ExplicitPrivate Type Customer    CNumber As String    FName As String    LName As String    Address As String    City As String    State As String    Zip As IntegerEnd Type  Private Sub Form_Load() Dim x As Integer Dim Cust(4) As Customer    Do While Not DataC1.Recordset.EOF        Cust(x).FName = DataC1.Recordset!FName        Cust(x).LName = DataC1.Recordset!LName        Cust(x).Address = DataC1.Recordset!Address        Cust(x).City = DataC1.Recordset!City        Cust(x).State = DataC1.Recordset!State        Cust(x).Zip = DataC1.Recordset!Zip        Cust(x).CNumber = DataC1.Recordset!CNumber        DataC1.Recordset.MoveNext        x = x + 1    Loop Put #1, , Cust    End Sub

Error 91: Object Variable Or With Block Variable Not Set
I am using VB6 in school (as opposed to VB.Net at home), and I get this error when I try to set an element of an array of a user defined class to something after redimming it more thaan once. The code is:

Class Calculations:


VB Code:
...Private Sub SymSort(ByRef symArray() As Symbol)    Dim intCounter1 As Integer, intCounter2 As Integer, intLast As Integer    Dim symTemp As New Symbol, symTempArray() As New Symbol    ReDim symTempArray(0)    Call SetSym(symTempArray(0), symArray(0))    For intCounter1 = 1 To UBound(symArray)        intLast = symTempArray(0).Compare(symArray(intCounter1), symTempArray(0))        If intCounter1 > 1 Then            For intCounter2 = 1 To intCounter1 - 1                If intLast = 0 Then                    Call SymInsert(symTempArray(), symArray(intCounter1), intCounter2 - 1)                    Exit For                End If                Select Case symArray(intCounter1).Compare(symArray(intCounter1), symTempArray(intCounter2))                    Case -1                        Call SymInsert(symTempArray(), symArray(intCounter1), intCounter2 - 1)                        Exit For                    Case 1                        If intCounter2 = intCounter1 - 1 Then                            Call SymInsert(symTempArray(), symArray(intCounter1), intCounter2 + 1)                            Exit For                        End If                        intLast = 1                    Case 0                        Call SymInsert(symTempArray(), symArray(intCounter1), intCounter2 - 1)                        Exit For                End Select            Next intCounter2        Else            intCounter2 = 1            Select Case intLast                Case -1                    Call SymInsert(symTempArray(), symArray(intCounter1), intCounter2 - 1)                Case 1                    Call SymInsert(symTempArray(), symArray(intCounter1), intCounter2 + 1)                Case 0                    Call SymInsert(symTempArray(), symArray(intCounter1), intCounter2 - 1)            End Select        End If    Next intCounter1End Sub ... Private Sub SymInsert(ByRef symArray() As Symbol, ByVal symElement As Symbol, ByVal intPlace As Integer)    Dim intCounter As Integer    ReDim Preserve symArray(0 To UBound(symArray) + 1) 'The new element is not initilized, it is set to nothing    Call SetSym(symArray(UBound(symArray())), symElement)    For intCounter = UBound(symArray()) - 1 To intPlace Step -1        Call SymSwitch(symArray, intCounter, intCounter + 1)    Next intCounterEnd Sub Private Function SetSym(ByRef symSymbol1 As Symbol, ByRef symSymbol2 As Symbol)    symSymbol1.Token = symSymbol2.Token 'Error Occurs Here    symSymbol1.Cls = symSymbol2.Cls    symSymbol1.PrecedenceLevel = symSymbol2.PrecedenceLevel    symSymbol1.Tag = symSymbol2.TagEnd Function...


Class Symbol:


VB Code:
Option ExplicitPrivate strToken As StringPrivate tclCls As TOKENCLASSPrivate prePrecedenceLevel As PRECEDENCEPrivate strTag As String Public Property Let Token(ByVal vData As String)'used when assigning a value to the property, on the left side of an assignment.'Syntax: X.Token = 5    strToken = vDataEnd Property Public Property Get Token() As String'used when retrieving value of a property, on the right side of an assignment.'Syntax: Debug.Print X.Token    Token = strTokenEnd Property...Public Sub Class_Initialize()    strToken = ""    tclCls = 0    prePrecedenceLevel = 0    strTag = ""End Sub


I cannot seem to figure out how to get VB to initilize a new element of an array of a user defined class. Any help would be appriciated.

ERROR -- Object Variable Or With Block Variable Not Set
Okay this is the questions. I have 2 forms. I am passing the recordset in one form to the other since i need to use the same recordset.

This is the part of the code which pass the recordset


Code:
Private Sub cmbMLI_Click()
On Error GoTo Errhandler
MLI = cmbMLI.text

SetupGenericDataControl rsData
rsData.RecordSource = "select * from tbmso.msot_mlis where MLI = '" &
MLI & "'" ', db, adOpenStatic, adLockOptimistic
rsData.Refresh
txtDiscrip.text = rsData.Recordset("MLIDESC").Value

Exit Sub
Errhandler:
MsgBox Err.Description
Exit Sub
End Sub

Private Sub cmdAdd_Click()
On Error GoTo Errhandler
Set frmNew.Data.Recordset = rsData.Recordset
frmNew.Data.Refresh
Call LoadThisForm(MliNew, frmNew)
Exit Sub
Errhandler:
MsgBox Err.Description
Exit Sub
End Sub



Then in this is the second form,




Code:
Private Sub cmdCancel_Click()
Unload Me
End Sub

Private Sub cmdSave_Click()
On Error GoTo Errhandler

SetupGenericDataControl Data

intTmpMsg = MsgBox("Do you want to Save the Changes? ", vbYesNo,
"Save")
If intTmpMsg = 6 Then
'Data.Recordset.Edit
Data.Recordset.AddNew
Data.Recordset("mli").Value = txtMLI.text
Data.Recordset("MLIDESC").Value = txtDiscrip.text
Data.Recordset.UpdateRecord

If Not Data.Recordset.EOF Then Data.Recordset.MoveFirst
Do While Not Data.Recordset.EOF
frmMLI.cmbMLI.AddItem Data.Recordset("mli").Value
Data.Recordset.MoveNext
Loop
frmMLI.cmbMLI.ListIndex = 0
frmMLI.cmbMLI.SetFocus
Unload Me
End If

Exit Sub

Errhandler:
Do While Not Data.Recordset.EOF
If Trim(txtMLI.text) = Trim(Data.Recordset("mli").Value & "")
Then
MsgBox ("xxxxxxxxxxxxxxxxxxx")
Exit Sub
End If
Data.Recordset.MoveNext
Loop
MsgBox Err.Description
Exit Sub
End Sub




Everything works fine in the first form but when i try to do something in form 2 it thorws error

"Object variable or with block variable not set"


Any help regarding this?????

Error 91 - Object Variable Or With Block Variable Not Set
Error 91 - Object variable or With block variable not set.

I am getting this error in the routine below. I cannot pin-point the exact line as this error is occuring outside of VB and in the .EXE on another machine.

Can anybody spot what could be causing the problem?

Thanks a lot!


VB Code:
On Error GoTo errHandler     Dim smode As String        'This procedure will create all the groups for the current user.    'If a user switches session then this can be called again.        'setup default tabs    With TabControl1      .ImageList = ilsIcons      .AddTab "All Open Items", 18, , "allopenitems", 1000      .AddTab "Closed Items", 18, , "closeditems", 1000      .AddTab "Open/Closed Items", 18, , "opencloseditems", 1000    End With        Data1.RecordSource = "select * from groups order by 1,2 asc" 'run query    Data1.Refresh        If Option1.Value = True Then       smode = "sell"    Else       smode = "buy"    End If        Dim iloc As Integer    Dim scatname As String    Dim sprevgroup As String        Do While Not Data1.Recordset.EOF          If Data1.Recordset("group_mode") = smode Then            With TabControl1                .ImageList = ilsIcons                If sprevgroup <> Data1.Recordset("group_name") Then                   .AddTab Data1.Recordset("group_name"), 18, , Data1.Recordset("group_name"), 1000                   sprevgroup = Data1.Recordset("group_name")                End If            End With          End If       Data1.Recordset.MoveNext    Loop

Object Variable Or With Block Variable Not Set, ERROR
I am getting a Object Variable or With Block variable not set Error on this code, how do i go about fixing that. All that i have on the form is a combobox and a Adodc box. I get the error on the Trip.Recordset.Movefirst line, right under the y=0. Please help me fix this, please explain a fix for this i am new to this.

Thanks


Private Sub Form_Load()
Dim strdbName As String
Dim str$
Dim x As Integer
Dim y As Integer

strdbName = strpath & "Travel"
Trip.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=Travel;Initial Catalog=" & strdbName

y = 0
Trip.Recordset.MoveFirst

For x = 0 To Trip.Recordset.RecordCount - 1
If Trip.Recordset("Active") = True Then
cboTripName.List(y) = Trip.Recordset("TripName")
y = y + 1
End If
Trip.Recordset.MoveNext
Next x

cboTripName.Text = cboTripName.List(0)
Trip.Recordset.MoveFirst
str = "TripName = '" & cboTripName.Text & "'"
Trip.Recordset.Find str, , adSearchForward, 1

End Sub

ADO Error -- Object Variable Or With Block Variable Not Set
Although I've used the adodc object before with no problems, I now receive a "Object variable or With block variable not set" error.

My References:
Microsoft ADO Ext 2.5 for DLL & security
Microsoft Data Binding Collection
Microsoft Data Environment Instance 1.0
Microsoft Jet and Replication Object 2.5 Library
(I will be accessing both Access & SQL 7 databases)

My Components:
Microsoft ADO Data Control 6.0

My ADO properties:
adoReports.CommandTimeout = 60
adoReports.CommandType = adCmdText
adoReports.ConnectionString = gconSwitch
adoReports.ConnectionTimeout = 60
adoReports.CursorLocation = adUseServer
adoReports.CursorType = adOpenStatic
adoReports.LockType = adLockReadOnly
adoReports.MaxRecords = 0
adoReports.Mode = adModeShareDenyNone
adoReports.RecordSource = "Select * from Clients"

gconSwitch = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=Switch;Data Source=Server1"



I have tried changing properties and comparing properties with working code from other projects, to no avail.

I am beyond frustrated. I hope someone can help,
rlb_wpg

Object Variable Or With Block Variable Not Set (Error 91)
Hi All,

I have just recently come back to my VB program that was working a few months ago and have tried to run it only to get this message

=============================
Object variable or With block variable not set (Error 91)
=============================

I remember having a similar problem before but I can't remember how to fix it.

Here is the code causing the problem.

====================
Public Function LoadClinics()
'Declare all my variables
Dim sql As String
frmSplash.lblWarning.Caption = "Connecting To Server..."
DoEvents
sql = "SELECT pc_ClinicID, pc_ClinicName FROM sbt_ParticipatingClinics Order By pc_ClinicName"
Dim RS As ADODB.Recordset

Set RS = ExecuteSQL(sql)
frmSplash.lblWarning.Caption = "Loading Clinic Names..."
DoEvents
'Make sure Array Is empty
Erase ClinicArray
'Populate Array
If Not RS.EOF Then <----- Problem Here
ClinicArray = RS.GetRows
End If
'Clean up
sql = ""
RS.Close

End Function
====================

Error '91' Object Variable Or With Block Variable Not Set
i get the above message on the following line of code

Range(Cells.Find("Name").Address).Select

does anyone have any idea why this would happen?

Error 91 Object Variable Or With Block Variable Not Set :-S
I am getting a Error 91 object variable or with block variable not set :-S error with the following code and I was wondering if anyone can tell me why?

Code:

Dim FsoFileCheck as filesystemobject
 
If fsoFilecheck.FileExists(fpSaveFolder & " empcardsegment.dat") = True Then
    Kill (fpSaveFolder & "tempcardTempcardsegment.Dat")
 End If

Error # 91: Object Variable Or With Block Variable Not Set
I am creating a program with settings, and I want to get the windows user, and then get a path for the users temp folder so I can use that to store files. My module code is below.

Code:
Public Declare Function getUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Const MAX_BUFFER_LENGTH = 100
Private Path As String

Public Function WindowsUser() As String
Dim Buffer As String
Dim Result As Long
Buffer = String(MAX_BUFFER_LENGTH, "X")
Result = getUserName(Buffer, MAX_BUFFER_LENGTH)
WindowsUser = Mid(Buffer, 1, MAX_BUFFER_LENGTH)
Path = "C:Documents and Settings" & WindowsUser & "Local SettingsTemp"
End Function

Public Function SaveSetting()
If Not fso.FolderExists(Path & "App") Then fso.CreateFolder (Path & "App")
If fso.FileExists(Path & "AppSettings.txt") Then Call Kill(Path & "AppSettings.txt")

Open Path & "AppSettings.txt" For Output As #1

If FRMSettings.OPT1.Value = True Then
Print #1, "1"
ElseIf FRMSettings.OPT2.Value = True Then
Print #1, "2"
ElseIf FRMSettings.OPT3.Value = True Then
Print #1, "3"
End If

If FRMSettings.OPT4.Value = True Then
Print #1, "4"
ElseIf FRMSettings.OPT5.Value = True Then
Print #1, "5"
ElseIf FRMSettings.OPT6.Value = True Then
Print #1, "6"
End If

If FRMSettings.CHK1.Value = 1 Then
Print #1, "7"
Else
Exit Function
End If

Print #1, FRMSettings.LSTMsgType.Text
Print #1, FRMSettings.TXTMsg.Text

Close #1
End Function

Public Function GetSetting()
If Not fso.FileExists(Path & "AppSettings.txt") Then Exit Function

Open Path & "AppSettings.txt" For Input As #1
    FileContents = Input$(LOF(1), 1)
Close #1

TheLines = Split(FileContents, vbNewLine)

If TheLines(0) = "1" Then
FRMSettings.OPT1.Value = True
ElseIf TheLines(0) = "2" Then
FRMSettings.OPT2.Value = True
ElseIf TheLines(0) = "3" Then
FRMSettings.OPT3.Value = True
End If

If TheLines(1) = "4" Then
FRMSettings.OPT4.Value = True
ElseIf TheLines(1) = "5" Then
FRMSettings.OPT5.Value = True
ElseIf TheLines(1) = "6" Then
FRMSettings.OPT6.Value = True
End If

If TheLines(2) = "7" Then
FRMSettings.CHK1.Value = 1
Else
FRMSettings.CHK1.Value = 0
End If

FRMSettings.LSTMsgType.Text = TheLines(3)
FRMSettings.TXTMsg.Text = TheLines(4)
End Function


I am now getting a file/path access error when I try to create a file, see the red code above. I am quite sure the path is right.



Edited by - Rapidfire on 4/29/2007 12:48:31 PM

'Object Variable Or With Block Variable Not Set' Error
I have a VB6 application which is throwing an error 'Object variable or with block variable not set'. The strange thing is that this error is only appearing in our Production environment & only appears intermittently (less than 1% of times this line is executed). I cannot reproduce the error in my development environment. The error appears on line 120 below:

'Create the temporary folder
Dim objFileSystem
110 Set objFileSystem = CreateObject("Scripting.FileSystemObject")
120 If objFileSystem.FolderExists(m_strTempFolderPath & "Temp_JID" & lngJobID) Then

I found a Microsoft article (http://support.microsoft.com/kb/316478) which mentions this bug but it says it only applies to the following, not VB6:
•Microsoft Visual Basic 2005 Express Edition
•Microsoft Visual Basic .NET 2003 Standard Edition
•Microsoft Visual Basic .NET 2002 Standard Edition

Has anyone received this error and is the solution suggested by Microsoft a guaranteed fix for it? (since I can't seem to reproduce the error it's going to be hard to test the fix!)

Thanks,
joey80

Object Or With Block Variable Error
Whenever I get to the following line in my code I get the "Object variable or With block variable not set" error message. I have a table selected on my current sheet:


Code:
PTRange = "!R1C1:R" + _
Mid(Str(Selection.Rows.Count), 2) + "C" + _
Mid(Str(Selection.Columns.Count), 2)
It used to be inside a With Activesheet block, but I still get the error even if I remove it from the block.

My original code (before I messed with it to try and fix it) is:

Code:
With ActiveSheet
PTRange = .Name + "!R1C1:R" + _
Mid(Str(Selection.Rows.Count), 2) + "C" + _
Mid(Str(Selection.Columns.Count), 2)

.PivotTableWizard SourceType:=xlDatabase, SourceData:= _
PTRange, TableDestination:="", TableName:="Cat1"
End With

I get the error with this code as well. Help!

Object Variable Or With Block Not Set - Error #91
I am having a problem and was wondering if anyone has run into the same problem. I am running VB 6 (SP5) using RDO to access Orcale. The application was written in VB 4. I get this runtime Error 91 whenever the code below tries to excuite.

Does not work this way:

Sql = "update " & MTATableOwner & ".w_keys set emp_id=0 where emp_id = " & LTrim$(Str$(rsEmployees!Emp_ID))

Works this way:

sTemp = LTrim$(Str$(rsEmployees!Emp_ID))
Sql = "update " & MTATableOwner & ".w_keys set emp_id=0 where emp_id = " & sTemp


It seems to be something to do with using a RDO object in an concatenated string. Anyone run into this?

Thanks
David Wallace

Error -- Object Variable Or With Block Not Set
I receive an Object variable or With Block not set error sometimes when running the following code:

Function wordConversion(sFileName As String)
If wordApp Is Nothing Then
Set wordApp = CreateObject("word.Application")
End If

Set wordDoc = wordApp.Documents.Open(sFileName)

<<this is where the error gets highlighted>>
With Documents.Application.Selection
.WholeStory
.Font.Name = "Ariel"
.Font.Size = 9
End With
ActiveDocument.PageSetup.Orientation = wdOrientLandscape
sFileName = nameChange(sFileName)
ActiveDocument.SaveAs sFileName, wdFormatDocument
ActiveDocument.Close

Set wordDoc = Nothing

End Function

Any ideas why this error would occur only occasionally, and how to correct the problem?

Thanks

Object Variable Or With Block Variable Not Set (image To Mysql)
I am trying to add an image to MySQL (Blob field) and I am getting a Object variable or with block variable not set error. Also, how would I retrieve the image from the database and load it into a picturebox?

VB Code:
If Not pbUserPicture.Picture = 0 And Not txtUsername = vbNullString Then        'save image to database        With m_ADOStream            [hl].Type = adTypeBinary[/hl]            .Open            .LoadFromFile pbUserPicture.Tag            Debug.Print pbUserPicture.Tag            m_ADORs!UserPicture = .Read                    .Close        End With    End If

Run Time Erro - 91 Object Variable Or With Block Variable Not Set
I created a setup.exe of vb 6.0 thro PDW. It was created succesfully. I downloaded the set up on a pc whicj do not have VB and installed it and tried to access the screen thro menu it says type mismatch.
run time error 91. object variable or with block variable not set.

anyone with some ideas why this err?. pls hlp me. it's urgent

hi JeffB

As you said I think there is no such reason b'cos when I compiled the EXe , ran the setup file in the development environment this err was not generated. This came into picture only when I ran the setup on a different PC. If at all this is the cause of the err then it should have given me this err in the devl. environment itself. What do you say? & above all I'm just calling a form through MDI form & here it generates this err

this is my third post. Plz anyone of you help me out

Error &"Object Variable Or With Block Variable Not Set&"
Hi,
I was stuck in one VB problem. Please help me. Thanks

The program mainly searchs one table named "A" in the database ( MS 2000) "B". If no matching data is found until last record, then the program would call another form which lists all the data in the table "A".
In the main form, Data4's databasename is set "B", Data4's recordsource is set "A". This part works well.

Code in the main form:
......
If Data4.Recordset.EOF = True Then

MsgBox ("Data is not found in the database. ")

Form2.Show vbModal

End If
......

In the sub form Form2, a list box called List1 and a data object called Data1 are created. Data1's databasename is set "B" and Data1's recordsource is set table "A" too.

Code in the subform:
Private Sub Form_Load()
Data1.Recordset.MoveFirst
Do While Data1.Recordset.EOF = False
List1.AddItem Data1.Recordset.Fields(1)
Data1.Recordset.MoveNext
Loop
End Sub

But the error "Object variable or with block variable not set" came out in the line: Data1.Recordset.MoveFirst

I read the local window and found the "database" property of Data1 was "nothing". Why? Thanks for your help.

&"Object Variable Or With Block Variable Not Set&" Error??
Hi,

I have an Access 2000 db and I have a form (called "Progress") that displays progress while code from another form is doing a large amount of processing. I update this form by calling some of its Public subs, for example:

[Forms]![Progress].Setup min, max, step
'where Setup is a Public sub, that takes min, max, and step as parameters

So SOMETIMES when my code tries to call the above sub, I get this error:

"Runtime error 91: Object variable or With block variable not set"

But its not always.... usually after I have run the code on the main form at least once... so right now, the only way I continue is to completely close my db and then open it again because it usually works on the first use....

I have absolutely no clue why this is, and I can't seem to find much information...

Thanks so much to anyone who might have any ideas!!!

Error Msg &"Object Variable Or With Block Variable Not Set&"
Hi,

I am using vb6, and mysql database.
I'm getting this message "Object variable or with block variable not set" everytime I'm running my application.

Code error: (mark with "*" )


Code:
'Dim obj1 As Project1.Class1
'Set obj1 = New Project1.Class1

Private Sub cmdCancel_Click()
adc.Recordset.Cancel
Unload Me
End Sub

Private Sub cmdSearch_Click()
Dim k As Date


adc.RecordSource = "Select * from tbllog"
adc.Refresh

lv.ListItems.Clear

While Not adc.Recordset.eof

If adc.Recordset(0) >= dp1.Value And adc.Recordset(0) <= dp2.Value Then

lv.ListItems.Add , , adc.Recordset(0)
lv.ListItems(lv.ListItems.Count).SubItems(1) = adc.Recordset(1)
lv.ListItems(lv.ListItems.Count).SubItems(2) = adc.Recordset(2)
lv.ListItems(lv.ListItems.Count).SubItems(3) = adc.Recordset(3)

End If

adc.Recordset.MoveNext

Wend
End Sub

Private Sub Form_Load()
loadConf
adc.ConnectionString = connectString

dp1.Value = Date
dp2.Value = Date
End Sub

Private Sub Form_Unload(Cancel As Integer)

* adc.Recordset.Close


End Sub



I've never incountered this problem before, and I would appriciate your assistance.

Thank you,

Run Time Error 99:Object Variable Or With Block Not Set
Hi, i'm new here, wanna ask question about vb6.0 refer to the above title, after google by google i search for it, none are useful, here are my code snippet


Code:
Private Sub cmdSave_Click()

With adoSupply.Recordset
.AddNew
!sName = txtsName.Text
!Address = txtAddress.Text
!postcode = txtPostCode.Text
!City = txtCity.Text
!country = txtCountry.Text
!phone = txtPhone.Text
!fax = txtFax.Text
!email = txtEmail.Text
!service = txtService.Text
.Update

MsgBox "Save Successfull", vbCritical, "Error"
End With

End Sub


I search in google and someone says that its related to the declaration part which i'm not declare a variable, but actually, the adoSupply i already declare it in the form gui which is all the connection string already setup there, so, anyone got an idea?

Thanks in advance

Error 91: Object Variable Or With Block Varaible Not Set
"Error 91: object variable or with block varaible not set"

i am getting the above error while retrieving the index of selected row in listview

please help me out

Private Sub ListPersons_DblClick()

Dim row As Integer
Dim item As ListItem
Dim personid As Double
Dim bsuccess As Boolean
Dim msName As String


'Listpersons is the name of listview
row = ListPersons.SelectedItem.index
personid = ListPersons.ListItems(row)

End Sub

Error 91 Problem - Object Variable Or With Block Not Set.
I am getting a run-time error '91':
Object variable or with block not set.

Highlighted code is highlighted in red.


VB Code:
Private Sub Form_Unload(Cancel As Integer)'conn is declared at the top of the source code page as:'Private conn As ADODB.Connection''rs is declared at the top of the source code page as:'Private rs As ADODB.Recordset [color=Red]rs.Close[/color]Set rs = Nothing conn.CloseSet conn = NothingEndEnd Sub


Please advise (this is the only problem I am getting now.)
Note: I am using SSTab with two tabs, both forms on the content areas of the tabs use ADODC to access a MySQL database (everything else is working fine.)

I finally figured out how to configure the SSTab

Hope someone can advise (NewB)

Run Time Error '91' Object Variable Or With Block Not Set ?
Hi ,

when i try to run my VB application i get this error

"Run Time Error '91'
Object Variable or With Block not Set"

my application basically opens a chart inside a form.
based on the index number in the drop down combo box.
how can i handle this problem,would really appreciate
your help.part of my code looks is as below:
can anyone suggest me how to overcome this problem?

Private Sub cmdDefaultChart_Click()

Dim index As Integer

If (IsNumeric(frmThermoCouple.cmbTCType.Text) = False) Then
index = frmThermoCouple.cmbTCType.ListIndex

If (index = 0) Then

Dim xlWkb As Excel.Workbook
Dim xlSht As Excel.Worksheet
Dim xlApp As Excel.Application

'Hiding the form
frmThermoCouple.Hide

Set xlApp = New Excel.Application
'Opening an already existing file
Set xlWkb = xlApp.Workbooks.Open("C: est3.xls")
Set xlSht = xlWkb.Worksheets(1)

'Charts.Add
ActiveChart.ChartType = xlXYScatterLinesNoMarkers
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A5:I2693"), PlotBy _
:=xlColumns

ActiveChart.Visible = xlSheetVisible
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Dowel Guage"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Time"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Data"
End With

ActiveChart.Axes(xlCategory).Select
With Selection.Border
.Weight = xlHairline
.LineStyle = xlAutomatic
End With
With Selection
.MajorTickMark = xlOutside
.MinorTickMark = xlNone
.TickLabelPosition = xlLow
End With
' X - Axis
ActiveChart.Axes(xlCategory).Select
With ActiveChart.Axes(xlCategory)
.MinimumScale = 0
.MaximumScale = 1600
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlAutomatic
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With
' Y- Axis
ActiveChart.Axes(xlValue).Select
With ActiveChart.Axes(xlValue)
.MinimumScale = -300
.MaximumScale = 300
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlAutomatic
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With

'Copying the chart from clipboard to the Image control
'in the form named "Form1".

ActiveChart.ChartArea.Select
ActiveChart.ChartArea.Copy

Form1.Image1.Picture = Clipboard.GetData(vbCFBitmap)
Form1.Image1.Top = 200
Form1.Image1.Left = 1000

Form1.Width = Form1.ScaleX(Form1.Image1.Width, vbPixels, vbTwips)
Form1.Height = Form1.ScaleY(Form1.Image1.Height, vbPixels, vbTwips)

Form1.Show

End If

If (index = 1) Then

Dim xlWkb1 As Excel.Workbook
Dim xlSht1 As Excel.Worksheet
Dim xlApp1 As Excel.Application

'Hiding the form
frmThermoCouple.Hide

Set xlApp1 = New Excel.Application
'Opening an already existing file
Set xlWkb1 = xlApp1.Workbooks.Open("C: est3.xls")
Set xlSht1 = xlWkb1.Worksheets(1)


ActiveChart.ChartType = xlXYScatterLinesNoMarkers
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A5:I2693"), PlotBy _
:=xlColumns

ActiveChart.Visible = xlSheetVisible
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Temp Rise"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Time"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Load"
End With

ActiveChart.Axes(xlCategory).Select
With Selection.Border
.Weight = xlHairline
.LineStyle = xlAutomatic
End With
With Selection
.MajorTickMark = xlOutside
.MinorTickMark = xlNone
.TickLabelPosition = xlLow
End With
' X - Axis
ActiveChart.Axes(xlCategory).Select
With ActiveChart.Axes(xlCategory)
.MinimumScale = 0
.MaximumScale = 850
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlAutomatic
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With
' Y- Axis
ActiveChart.Axes(xlValue).Select
With ActiveChart.Axes(xlValue)
.MinimumScale = -150
.MaximumScale = 250
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlAutomatic
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With

'Copying the chart from clipboard to the Image control
'in the form named "Form1".

ActiveChart.ChartArea.Select
ActiveChart.ChartArea.Copy

Form1.Image1.Picture = Clipboard.GetData(vbCFBitmap)
Form1.Image1.Top = 200
Form1.Image1.Left = 1000

Form1.Width = Form1.ScaleX(Form1.Image1.Width, vbPixels, vbTwips)
Form1.Height = Form1.ScaleY(Form1.Image1.Height, vbPixels, vbTwips)

Form1.Show

End If

End if

End Sub

Copyright © 2005-08 www.BigResource.com, All rights reserved