1

I have some code which has worked in multiple installations for about a year. Today im doing a small change to a control and then another control seems to have developed an issue. When at runtime im getting a 91 error object variable or with block variable not set.

I therefore looked at the problem line which is: -

If Screen.ActiveForm.name = "frmFoutmelding" Then Exit Sub

so I noticed the name was lowercase. if i delete .name and rehit the "dot" then it shows me i can use .Name but as soon as i move from this line it drops back to .name

I've checked for instances of name and it appears everywhere in the code in different modules but i cant find if i have accidentally defined this lowercase name anywhere?

Googling doesn't seem to show much but i feel Im googling the wrong terms


chaps - thanks for your suggestions - this was the first instance of the lowercase name and searching as Jim suggested didn't reveal anything I'm afraid. What I did discover was that this was suddenly being run before any forms had actually been displayed and so the count was 0. I therefore, did an on error to check the form count and exit the sub if it =0 then if not to carry on with the line I thought I was having issues with.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Simon Wait
  • 65
  • 1
  • 4
  • 1
    Are you sure Screen object isn't Nothing when you run into this error? http://www.vbforums.com/showthread.php?494781-VB6-Current-active-form . Property names in VB6 shouldn't be case sensitive so name vs Name shouldn't cause an error. If you think that's the issue, close all code windows, close VB6, use a text editor to change it back to Name, open your project and compile. If you don't open that code file in the IDE, it shouldn't change it back to name. – Marc Jun 25 '17 at 14:16
  • You could also add checks to see if Screen or ActiveForm are Nothing and throw up a message box. Then if you run into the error again you can see if one of those were Nothing and the actual cause of the problem. – Marc Jun 25 '17 at 14:18
  • 1
    Wow, everyone is so fixated on name vs. Name. VB6 is case insensitive! And the IDE is notiously bad at confusing auto-complete sometimes. Ignore that! [Here](http://www.vbforums.com/showthread.php?494781-VB6-Current-active-form) is the exact same issue. Sometimes ActiveForm is nothing. [Here](http://vbcity.com/forums/t/48291.aspx) is a possible solution using windows API, but you will need to inspect maybe the form title. – djv Jun 26 '17 at 02:16
  • The issue of case of variables is covered fully here: https://stackoverflow.com/questions/1064858/stop-visual-basic-6-from-changing-my-casing but this will not cause any runtime or compiler errors, it is just a maintenance issue. Your runtime error is due to something else. – StayOnTarget Jun 28 '17 at 11:30

2 Answers2

1

It's likely that you did create a new variable or property called (lower case) name, or that some included reference did the same. It's possible to use reserved words as variable names in some cases, but it requires taking specific steps.

I would first search your code for instances of name As to see if you created a variable (this assumes you use Option Explicit, which is a must IMO). Then search for Property*name with * as a wildcard.

If those fail you could try unchecking references or components to see if any of them define name. If none of that finds anything, please post back here.

Jim Mack
  • 1,070
  • 1
  • 7
  • 16
0

Jim Mack covers a lot of the potential issues. I think another is if you typed a lower case '.name' in association with Activeform at some point earlier in the same code module - the VB6 IDE checks in the current module and uses that to define what case to use. Look further up the same code module (sub or function).

Ultimately, check what changes you made by comparing the old source to the new in a file comparison tool like windiff - you do have backups, right?

Vanquished Wombat
  • 9,075
  • 5
  • 28
  • 67