Solved Bang v Dot, and Compiler? (1 Viewer)

Gasman

Enthusiastic Amateur
Local time
Today, 14:24
Joined
Sep 21, 2011
Messages
14,053
A user on another forum had code similar to the code below.
I created mine to test my theory was correct even with an evident Compile error message of 'Method or data member not found'

Code:
Private Sub Command15_Click()
If IsNull(Me!txtResult1) Then
    MsgBox "Test is null"
    Me.txtResult1.SetFocus
End If
End Sub

The error occurs on the SetFocus line.

My question is why did the compiler not pick it up on the IsNull line?
I must admit, I mostly always used the dot when I coded, unless it was for something like Forms! etc, however it seems a little flaky if you use the bang as above and the compiler does not flag it.?

Please do not ask me why he used one method and then the other, I would have no clue. :)
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 09:24
Joined
Feb 28, 2001
Messages
27,003
This comes up from time to time.


Read through this and see if it helps.
 

Isaac

Lifelong Learner
Local time
Today, 07:24
Joined
Mar 14, 2017
Messages
8,738
This is going to be a crude "way" of saying it, but I think is more or less correct anyway.

To me, the compiler seems to be closely associated with intellisense. If it didn't give you intellisense........the compiler does not know about it. Esp. when comes to members of objects or classes

Now there are probably exceptions to this, but I mean it as a rule of thumb, not an absolute.
 

Gasman

Enthusiastic Amateur
Local time
Today, 14:24
Joined
Sep 21, 2011
Messages
14,053
Well, blow me down. I know I have a bad memory, but still.? :(
I posted a similar question two years ago :(

I think this settles it and confirms the issue on the other forum.

The bang is shorthand for a Late Bound Reference to the default member of an object. Being Late Bound, any error due to an invalid reference will not be picked up during the compile. Exactly what the default member of an object is depends on the object but Properties and Methods are never the default so the dot must always be used for them.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 10:24
Joined
May 21, 2018
Messages
8,463
See number 2 for how the bang works. It is passed as an argument at runtime, and this explains the whole reason why you would need it.
 

Isaac

Lifelong Learner
Local time
Today, 07:24
Joined
Mar 14, 2017
Messages
8,738
Thanks for the explanation. I guess that's why I associated the bang + intellisense with the Compiler's knowing or not knowing.............late/early binding. Makes sense.
 

Users who are viewing this thread

Top Bottom