Object Variable Not Set Error

Object Variable Not Set Error

Anonymous
Not applicable
1,896 Views
26 Replies
Message 1 of 27

Object Variable Not Set Error

Anonymous
Not applicable
I'm making a VBA to make it easier and more user friendly to edit the attributes in our titleblock. I made a form with a bunch of textboxes and when it loads up, it fills in the textboxes with the attributes.

The program runs ok, but after it terminates, it gives the error message:

Run-time error '91':
Object variable or With block variable not set.

I'm not using a With block, so I assume I'm not setting something right.

Any ideas?



Private Sub UserForm_Initialize()

Dim oblkRef As AcadBlockReference
Dim objFnd As AcadEntity
Dim atts As Variant

For Each objFnd In ThisDrawing.PaperSpace

If TypeOf objFnd Is AcadBlockReference Then
Set oblkRef = objFnd
If StrComp(UCase(oblkRef.Name), "TITLEBLOCK", 1) = 0 Then
Exit For
End If
End If
Next objFnd

atts = oblkRef.GetAttributes
TextBox0.Text = atts(0).TextString
TextBox1.Text = atts(1).TextString
TextBox2.Text = atts(2).TextString

Me.Show

End Sub

I'm sure it's something "basic" (sorry) but I'm new to VBA.
Thanks.
0 Likes
1,897 Views
26 Replies
Replies (26)
Message 21 of 27

Anonymous
Not applicable
Try the next step further
Bear in mind that A2007 version is do not
allowed for me to set blank spaces in the tag names
The SAVE button code you can write similarly
Let me know if you should't

~'J'~
0 Likes
Message 22 of 27

Anonymous
Not applicable
I finally tested my idea, and it works nicely. I used TextBox.TabIndex as my indicator, and it pulled everything up just right. I used TextBox.Tag first, and it worked too, but I changed my mind and went with TabIndex. Both will work if applied properly.

'///Load up TextBoxes with Attribute Info
Dim ctlObj As Control, tbxObj As Control
Dim indx As Long
For Each ctlObj In Me.Controls
If TypeOf ctlObj Is TextBox Then
Set tbxObj = ctlObj
indx = tbxObj.TabIndex
tbxObj.Text = atts(indx).TextString
End If
Next

'///Dump Info from TextBoxes Back to Attributes
Dim ctlObjOut As Control, tbxObjOut As Control
Dim indxOut As Long
For Each ctlObjOut In Me.Controls
If TypeOf ctlObjOut Is TextBox Then
Set tbxObjOut = ctlObjOut
indxOut = tbxObjOut.TabIndex
attsOUT(indxOut).TextString = NullCheck(tbxObjOut.Text)
End If
Next

I had a problem when a textbox was empty. It would choke on a Null, so I made a function to replace the Null with a Space.

Public Function NullCheck(str As String) As String
'///Check If TextBox has Null Entry (Nothing)
'///If Null, Add Space
Dim ChkStr As String
If str = "" Then
ChkStr = " "
Else
ChkStr = str
End If
NullCheck = ChkStr
End Function


Thanks for all your help.
I'm trying to get on and answer some questions if I can.
0 Likes
Message 23 of 27

Anonymous
Not applicable
You must've posted right after I did. Check out the code above.

Thanks again.
0 Likes
Message 24 of 27

Anonymous
Not applicable
I'm still getting the @#%& error! But it happens after the program completes successfully, and unloads the form. It works fine, but this error shows up. Can I just ignore the error and make it not give me the message?
0 Likes
Message 25 of 27

Anonymous
Not applicable
wheres the code that calls the form?
whats in the terminate sub in the form?
error messages are your friend
turning them off is not the solution to the errors that cause them
:-)
Mark

wrote in message news:5752725@discussion.autodesk.com...
I'm still getting the @#%& error! But it happens after the program completes
successfully, and unloads the form. It works fine, but this error shows up.
Can I just ignore the error and make it not give me the message?
0 Likes
Message 26 of 27

Anonymous
Not applicable
It's better now. I went in and wrestled with it some more. I really can't say what I did right, but it works again, so I'm just gonna be happy.:)
0 Likes
Message 27 of 27

Anonymous
Not applicable
And we all here are happy with you :))
Sorry, I missed this thread

~'J'~
0 Likes