Accessing A Variable Name By A Variable
I know you can call a function by name or by it's name in a variable. My question is can that also be done for named variables or Const's?
To illustrate
I have the following data strings in my code:
Private Const s1 = "some text here" Private Const s2 = "some text here" Private Const s3 = "some text here" Private Const s4 = "some text here" etc etc Private Const s356 = "some text here"
I cannot put the data in an array. That is out of the question. I can only put the data in a series of Const's like shown above.
I need some way, if possible, to access the data from each Const without having to explicitly namming each Const. Something like this
For q = 1 to 356 MyDataString = MyDataString & "s" & q Next q
Now I know the above will put "s1", "s2", "s3",...."s356" in MyDataString but I need the actual data from these Const's.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Accessing A Variable With Its Name
Is it possible to have a string with a name of a variable, and use that to access information about a variable with that name?
For example, a function might take as an argument the name of a variable ("TextBox1") and then somehow translate that into accessing the object TextBox1. Or another example, if you created an array called <itemname>_Array (e.g. TextBox1_Array, Label1_Array, etc) then if you had a string "TextBox1" could you write your code to append "_Array" and then access the variable?
This probably sounds really weird but I have this gigantic userform with tons of features and I want to write some generalized functions for updating the fields, resetting the default values, etc. and it seemed like this would be handy.
thanks a lot,
Rachel
Accessing VB Variable With C++?
Is it possible to create a variable in visual basic and then call a function from a DLL created in C++ that will access that variable? Like in the DLL, C++ uses a pointer to memory where the variable is stored and then changes it. Would that work?
Accessing Variable
I have not coded in VB for awhile or very often, actually I seem to be able to make more money in other areas. Still I needed to write this code in VB and I can not seem to access the value of a variable. I need to access the value of the variable called swSubFeat in the following code and include the value of the variable in the filename variable. What I have does not work, Any suggestions?
VB Code:
Option ExplicitSub MacroFeature() Dim swApp As SldWorks.SldWorks Dim swSketch As sketch Dim SelectedPoint As SketchPoint Dim Doc As SldWorks.ModelDoc2 Dim ThisFile As String Dim Methods(8) As String Dim Names As Variant Dim Types As Variant Dim Values As Variant Dim editBody As body2 Dim SketchName As Boolean Dim PointArray As Variant Dim LocationData As String Dim swModel As Variant Dim solution As String Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc Set Doc = swApp.ActiveDoc 'Define the routines to call ThisFile = swApp.GetCurrentMacroPathName Methods(0) = ThisFile Methods(1) = "MacroFeature_Module1" Methods(2) = "swmRebuild" Methods(3) = ThisFile Methods(4) = "MacroFeature_Module1" Methods(5) = "swmEditDefinition" Methods(6) = "" 'A security routine is optional Methods(7) = "" Methods(8) = "" Names = Empty Types = Empty Values = Empty Set editBody = Nothing 'Insert the macro feature Doc.FeatureManager.InsertMacroFeature "Link Filename to Description", "", (Methods), Names, Types, Values, editBody, swMacroFeatureByDefault End SubSub TraverseFeatureFeatures(swFeat As SldWorks.Feature, nLevel As Long) Dim swSubFeat As SldWorks.Feature Dim swSubSubFeat As SldWorks.Feature Dim swSubSubSubFeat As SldWorks.Feature Dim sPadStr As String Dim i As Long For i = 0 To nLevel sPadStr = sPadStr + " " Next i While Not swFeat Is Nothing Debug.Print sPadStr + swFeat.Name + " [" + swFeat.GetTypeName + "]" Set swSubFeat = swFeat.GetFirstSubFeature While Not swSubFeat Is Nothing Debug.Print sPadStr + " " + swSubFeat.Name + " [" + swSubFeat.GetTypeName + "]" Set swSubSubFeat = swSubFeat.GetFirstSubFeature While Not swSubSubFeat Is Nothing Debug.Print sPadStr + " " + swSubSubFeat.Name + " [" + swSubSubFeat.GetTypeName + "]" Set swSubSubSubFeat = swSubFeat.GetFirstSubFeature While Not swSubSubSubFeat Is Nothing Debug.Print sPadStr + " " + swSubSubSubFeat.Name + " [" + swSubSubSubFeat.GetTypeName + "]" Set swSubSubSubFeat = swSubSubSubFeat.GetNextSubFeature() Wend Set swSubSubFeat = swSubSubFeat.GetNextSubFeature() Wend Set swSubFeat = swSubFeat.GetNextSubFeature() Wend Set swFeat = swFeat.GetNextFeature Wend End Sub Function swmRebuild(app As Variant, Part As Variant, Feature As Variant) As Variant Dim Component As ObjectDim retval As BooleanDim mypart As ObjectDim filename As StringDim config_name As StringDim shortfilename As StringDim longfilename As StringDim swApp As SldWorks.SldWorksDim solution As StringDim swSubFeat As SldWorks.Feature Set swApp = Application.SldWorksSet mypart = swApp.ActiveDocsolution = (swSubFeat)config_name = ""'filename = Part.GetTitle()filename = solution longfilename = Len(filename)shortfilename = Left(filename, longfilename - 0) & "" On Error Resume Next retval = mypart.DeleteCustomInfo2(config_name, "Description") retval = mypart.AddCustomInfo3(config_name, "Description", 30, shortfilename) End Function Function swmEditDefinition(app As Variant, Part As Variant, Feature As Variant) As VariantMsgBox "Nothing to edit"End Function
Accessing Properties With A Variable
hi all,
i'm just coding a custom datarepeater control and am stuck with this:
is it possible to set a usercontrol's property through a variable?
eg. if i have a variable:
myvar = "username"
i need to access the usercontrol's username property like
mycontrol.(myvar) = "bla"
but of course it doesnt work that way.
any help how i could do it or if its possible at all?
thanks,
tom
ADO Accessing A Field Thru A Variable
Hi all,
Is there any way to access the field FLD="TEMP" without getting the error Ado!FLD not found ..?
The following should be interpreted as dt=ado!TEMP but Ado looks for the field FLD which do NOT exist...
dim FLD as string, dt as string
FLD="TEMP"
dt=ado!FLD
thanks !
Accessing Variable In Component
I would like to know if there is an other way than Property to access variable inside a component.
The reason why a asking that is because I have an Array of value that I want to access in design time as ReadOnly from other components in the same form.
Accessing Public Variable
Hello frieds
I am facing a problem in the vb.net 2003 windows programing which i am doing for the first time otherwise i usually do web development in asp.net. Basically i am facing problem with the things i do differently in the asp.net.
I am having a single form and three supporiting module.
1. I have defined the variable as public in the forms vb page and i wand to access to it from one of the three modules.
2. where should i declare my connection string so i can access it from any page.
please provide answar with code.
Any help would be great.
thanks
amit
Accessing A Variable On A Form
Hi,
I am using the following code
Dim frmX As newdisp
Set frmX = New newdisp
frmX.Show
but, on the newdisp form, i have a listbox, which i need to click on. which launches another form, which access the record it needs using newdisp.listview1.SelectedItem
this works fine the first time. but when i click on another item in the listbox, the newdisp.listview1.SelectedItem still have the vaibale from the first click, is there a way around this?
thanks
Accessing Public Variable In DataReport
Hi Gurus
In the form, from which I'm calling the DataReport.Show, I'm using three
variables (A, B, C) as Public type. I want to print their values in Page/
Report Header Portion. Please guide me how can the values of these public
variables be accessed in DataReport.
Thanks & with regards
Sincerely yours
RAJIV KUMAR THAKUR
Scientific Officer & D.I.A.
National Informatics Centre
(Min. of Comm. & IT - GOI)
O/o Deputy Commissioner - Kullu
Himachal Pradesh - INDIA - 175 101
Phone: 91 1902 224130 (Office)
Accessing Recordset Field Using Variable? Possible? Plz Read
i want to reference a recordset's field using a variable for the fieldname instead of having it hard coded..
so i want to do this:
fieldname = "field1"
myRecord!fieldname = "bla"
but access isn't evaluating fieldname, and is taking 'fieldname' to be the acual name of the field, instead of having it evaluate to 'field1'first.
i've also tried wrapping the statement in Eval() but that doens't work either. help/suggestions would be greatly appreciated!
Accessing Database From Program To Obtain Variable
Where should I be looking for information on accessing a database file through VB code.
Is it ODBC or Dao. I 'm confused because they are such large topics. I dont need to change data just access it for my program . Just give me a starting point please...
thanks
Edited by - sempos on 10/7/2003 6:04:03 PM
Accessing Events Of A Control Which Is Declared As A Variable
Hi,
I want to call the click event of a menu which is being declared as a variable. How do i do this
Dim m
Dim MenuName As String
MenuName = "mnuAccMaster"
For Each m In MDIForm1
If TypeOf m Is Menu Then
If m.name = MenuName Then
-----------------------------------------------------------------
Call m_click ---- I am getting the error here
What is the coding for this
-----------------------------------------------------------------
End If
End If
Next
I have a menu called mnuAccMaster in Mdiform
I want to call the click event of this menu.
How To Assign A Cell/Range Address In A Variant Type Variable To Another Variable
Sir,
I have the following piece of code which looks up a certain date in several wrksheets and aims to return the value in a cell located in the next two columns (same row) where my look up value is.
For i = 1 To 23
Worksheets(strFilename(i)).Activate
Range("C4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.NumberFormat = "[$-409]dd-mmm-yy;@"
Dim strFilename(1 To 23) As String, strFilename2(1 To 23) As String, strPath As String
Dim dtActProg As Date
Dim rngSearch As Variant
Dim c As Variant, c1 As Variant
Set rngSearch = ActiveCell.CurrentRegion
With Worksheets(strFilename(i)).Range(rngSearch.Address)
Set c = .Find(dtActProg, LookIn:=xlFormulas)
If Not c Is Nothing Then
Sheets("Sheet1").Select
Cells(i, 2) = c.Value
' Returns the date I enter via an Inputbox in the privous section of my code
' In the remaining section of my code I need to assign the address of the cell located in the 2nd column next to where code looks up date value assing it to a variable and return the value on Sheet1 next to where code writes c.vale
For example if c.address="$A$2" then c1.address must ve "$A$4 which will be listed on Sheet1 together with my dates entered via ListBox
End If
End With
Next i
Thanks,
Fatih Can
Petroleum Eng., MSc.
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
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
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
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!
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
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.
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
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 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
Speed Issues With Global Variable Vs. Local Variable
I have a global integer variable that is assigned a number towards the beginning of the program. Farther on in the program I have a subroutine that will be accessing this value repeatedly throughout the procedure. My question is, should I: A) call the global variable each time I need to access that value; or B) create a local variable at the beginning of the subroutine in question, fill the local variable with the contents of the global one, and then just refer to the local variable each time I need to access that value in the subroutine? I'm wondering mainly if there will be any performance/speed issues between the two options.
Thanks!
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
Difference Between Global Variable And Public Variable Is BAS Module
What is the difference between a Global Variable declared and a public varibale declared in BAS Module
for example in a BAS Module MyModule I am declaring the two varibles as follows
Public MyPublicName as String
Global MyGlobalName as String
Now i can use both the variable through out the project.
If so what is the difference between these two variables.
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
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
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
How To Use Outputs Variable As An Input Variable For Further Simulation?
Hello Dear Friends
I have this code in the form
.Inputs.Add "Input13", "RISKPert(Outputs(4), Outputs(9),0.023)"
and this code in class module
.Outputs(4) = 1 / .Inputs(9)
.Outputs(9) = 1 - .Inputs(12)
I want to use outputs 4 and 9 in my input 13. when I write the code in the above form the simulation doesn't run. It gave an error warning of invalid string.
The question is how can I put outputs 4 and 5 as a variable in input 13 and run the simulation? any help is appreciated
regards,
biruk
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"> </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
Making Pointer Of A Long Variable For Another Variable
My brains are having issues, so here we go:I have a Long variable that I want to contain a pointer value.I want to change the value of this variable to be pointer value to anywhere in the memory.The value of another Long variable should change to be the contents of the pointer.I just can't get my head to do it... very simple, just a change to one pointer value in memory, but how to do that?
Object Variable Or With Variable Not Set... Prevent This Error?
Im writing a program that parses only certain pages a user is viewing, then send information to a server
In my NavigateComplete2 event, I make sure the ie.busy = False and the url is the type of page I want
Code:
Dim hDoc2 As MSHTML.HTMLDocument
'Other Code
Private Sub ie_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
If ((InStr(1, ie.LocationURL, "page1.php") > 0 Or InStr(1, ie.LocationURL, "page2.php") > 0) And ie.Busy = False) Then
Set hDoc2 = ie.document
Dim tmp As String
Dim tmp2 As String
tmp = hDoc2.body.innerHTML
That last line is where it throws the error. It does it once every 20 times
(mostly on page2.php), and Im not really sure why. Is there another line or something I can put in the If statement to make sure the object is set?
I searched for about 20 minutes and found nothing
Sorry, Im really bad at VB. My specialty is php :/
Thanks
Bear
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.
|