Evaluate("1") gives error 438 - vba

I have few "Why?"s about evaluate...
Sub TestEvaluate()
Dim Tag As String
Tag = "5"
Tag = Evaluate(Tag) 'works fine
Tag = "1"
Tag = Evaluate(Tag) 'error 438 wrong property or method(-> my 1st "Why?")
But ok i can handle it:
Tag = "1"
Tag = [Tag] 'works fine
Now I need to evaluate a property of some object:
Dim Object As cObject
Set Object = New cObject
Object.pProperty = "5"
Tag = Evaluate(Object.pProperty) 'Works fine
And again the same problem as above:
Object.pProperty = "1"
Tag = Evaluate(Object.pProperty) '438 wrong property or method
But now i'm traped, becouse:
Tag = [Object.pProperty] 'generates error 13 type mismatch(-> my 2nds "Why?")
Is there some solution without the need to use a new variable?
Dim TempTag As String
TempTag = Object.pProperty
Tag = [TempTag] 'everything fine again
End Sub
i found out, in my case VBA.Evaluate("1") generates an object according to
debug.print VBA.VarType(evauate("1"))
It`s just a bug? (win8.1 xl2007)

I put the expression into brackets and the problem disappeared; works fine now:
Tag = Evaluate("(" & Tag & ")")

This is better solution for me:
Tag = Evaluate(Tag & "+0")
It is a solution for the Error 2015 when the Tag="" as well.

Related

.FilterOn Method Not Working

K Access guru's. I have a module that requery's a main form, then set's a filter based on a value in a field, and requery's the subforms with that filter. The problem is when I set subform.FilterOn = True, it doesnt do anything and returns False. I'd rather not upload the whole solution. But heres a screenshot of the code with the highlighted part showing the discrepancy. Below is the code for copy/paste purposes. Why is this not working?
Private Sub Combo7_AfterUpdate()
Dim strSQL As String
Application.Echo False
strSQL = "[APN] = " & Str(Nz(Me![Combo7], 0))
DoCmd.ApplyFilter wherecondition:=strSQL
Me![Combo22].Requery
Me![Combo22] = Me![Text24]
Dim val As String
Dim subform1 As Form
Dim subform2 As Form
Dim subform3 As Form
val = Me![Text24]
Set subform1 = Me.qPayment_subform.Form
Set subform2 = Me.qRefundWriteOff_subform.Form
Set subform3 = Me.qRetnCHK_subform.Form
subform1.FilterOnLoad = True
subform2.FilterOnLoad = True
subform3.FilterOnLoad = True
subform1.FilterOn = True
subform2.FilterOn = True
subform3.FilterOn = True
subform1.Filter = "PeriodID = " & val
subform2.Filter = "PeriodID = " & val
subform3.Filter = "PeriodID = " & val
subform1.Requery
subform2.Requery
subform3.Requery
Application.Echo True
End Sub
Give subform container control a name different from the object it holds. For instance, if the form is named frmOrderDetails name the container ctrDetails. Then maybe using the container name in setting the object variables will work. If not, consider eliminating the variables and just referencing the container name.
With Me
...
.ctrDetails.Form.FilterOn = True
...
End With
I know this means repeating .Form but it will be fast edit.
In any case, set the Filter property before FilterOn.
Also, FilterOnLoad and Requery are not necessary.

Setting CheckBoxes from another userform in VBA

I have a userform which contains a number of checkboxes from 1 to 100. I have written some very simple code so that when you submit the form it creates a binary string that represents the state of those 100 checkboxes, where 0 is false and 1 is true. The code to do this is here:
Private Sub BusRulesSubmit_Click()
Dim myBinaryString As String
Dim nm As String
Dim c As Control
For busRuleIdx = 1 To 100
nm = "CheckBox" & busRuleIdx
Set c = Controls(nm)
If c.Value = True Then
myBinaryString = myBinaryString & "1"
Else
myBinaryString = myBinaryString & "0"
End If
Next
msgBox myBinaryString
End Sub
I now want to open this Userform from another form, where I have a similar binary string, and use this string to set the values of the checkboxes to true or false as appropariate. However I am having issues when setting my control. The code is here:
Private Sub populateBusRules()
Dim c As Control
Dim myBRBinary As String
myBRBinary = "000000000011100000000000000000000000000000000000000000000000000000000010000000000000000000000000000"
For busRuleIdx = 1 To 100
nm = "BusinessRules.CheckBox" & busRuleIdx
Set c = Controls(nm)
If Mid(myBRBinary, buRuleIdx - 1, 1) = 1 Then
c.Value = True
Else
c.Value = False
End If
Next
End Sub
When I run the above, I get a runtime error "Could not find the specified object" and when going to debug it highlights this problem where the code states "Set c = Controls(nm)" - and I can see that it is failing in the first round of the loop i.e. where nm = "BusinessRules.CheckBox1"
Interestingly if I run the code "Set c = Controls(BusinessRules.CheckBox1)" I get no such issue.
Any help would be much appreciated.
Thanks,
Paul.
I think the BusinessRules is giving you the issue. In the Controls collection, there is no Control named "BusinessRules.CheckBox1", only one named "CheckBox1" within the BusinessRules.Controls collection. Assuming there aren't other issues mentioned in the comments above (like the form being closed before this is called), then this should fix your issue

Invalid argument tag

I am doing some customization of block insertion in Autocad. When setting up the attributes, I am getting an error in my procedure:
"Invalid argument Tag in setting TagString"
The code is as follows:
Sub Ch10_GettingAttributes()
' Create the block
Dim blockObj As AcadBlock
Dim insertionPnt(0 To 2) As Double
insertionPnt(0) = 0
insertionPnt(1) = 0
insertionPnt(2) = 0
Set blockObj = ThisDrawing.Blocks.Add _
(insertionPnt, "TESTBLOCK")
' Define the attribute definition
Dim attributeObj As AcadAttribute
Dim height As Double
Dim mode As Long
Dim prompt As String
Dim insertionPoint(0 To 2) As Double
Dim tag As String
Dim value As String
height = 1#
mode = acAttributeModeVerify
prompt = "Attribute Prompt"
insertionPoint(0) = 5
insertionPoint(1) = 5
insertionPoint(2) = 0
tag = "Attribute Tag"
value = "Attribute Value"
' Create the attribute definition object on the block
Set attributeObj = blockObj.AddAttribute(height, mode,_
prompt, insertionPoint, tag, value)
End Sub
What would cause this error?
Well, the error message is rather explicit, you have an "Invalid argument Tag in setting TagString"
So simply get rid of space in the tag value and you should be good to go. It doesn't support spaces.
tag = "Attribute Tag" 'BAD
tag = "AttributeTag" 'OK

Using XMLDocument - How to change an attribute value

I am trying to replace a found attribute with a new value, but can not seem to get it....
XML Example
<department sysid="1" name="a" minAmt="0.00" maxAmt="0.00" isAllowFS="0" isNegative="0" isFuel="0" isAllowFQ="0" isAllowSD="0" isBL1="0" isBL2="0" isMoneyOrder="0">
<category sysid="0" />
Code
For Each node In xmldoc.SelectNodes("//department")
'For Each node In nodeDepartment
Dim a = node.getAttribute("isFuel").ToString
If a = 0 Then
node.ChildNodes.Item(1).Attributes.getNamedItem("sysid").Value = "400"
Dim sName As String = node.getAttribute("name").ToString 'I get the value here
If Trim(sName) = "" Then
node.Attribute("name") = "A" 'I Error on this line
End If
End If
lCount += 1
Next
You need to use the SetAttribute Method instead of GetAttribute.
If Trim(sName) = "" Then
node.SetAttribute("name", "A")
End If

Enable / disable menu items using session in vb.net

If Session IsNot Nothing And Session("Admin") = "ftghgy" Then
Dim rptMenuItem As MenuItem = Menu1.FindItem("Home")
rptMenuItem.Selectable = True
Label9.Text = ("Welcome")
Else
Label9.Text = ("Welcome " + "" + Session("UserName").ToString)
endif
I am getting this error...
"Object reference not set to an instance of an object" on this line "rptMenuItem.Selectable = True"
I and am not using a master page.
Well, then probably this line is returning null value :
Menu1.FindItem("Home")
Meaning that an item with id "Home" couldn't be found in your Menu1.
I think it must be integer Menu1.FindItem(Type)