Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

OpenArgs and DefaultValue

75 views
Skip to first unread message

croy

unread,
Jul 13, 2016, 1:25:01 PM7/13/16
to
In Access 2002, when opening a form from a command
button....

I use this code:

DoCmd.OpenForm stDocName, acNormal, ,
stLinkCriteria, _ acFormEdit, , Me.txtArchId

txtArchId is a key field, and it is a text field.

I'm trying to set the DefaultValue for txtArchId on the
opening form, but can't get it to work.

Do I need to do something different with the OpenArgs
statement on the first form because it is a text field?

--
croy

Mike P

unread,
Jul 13, 2016, 2:00:42 PM7/13/16
to
Hi croy,

The value of OpenArgs will be Null if the form stored in stDocName is already open in any view.

Try docmd.close stDocName immediately beore the open command.

Should _ acFormEdit be just acFormEdit?

I prefer Me!txtArchid to Me.txtArchid, exclamation mark instead of full-stop.

Is there an error message?

What is the value of OpenArgs? Try "debug.print OpenArgs" in the form's load event procedure.

Mike P

13/7/16

Patrick Finucane

unread,
Jul 13, 2016, 5:00:39 PM7/13/16
to
In your OnOpen or OnLoad events of the 2nd form (stDocName) you might want something like
IF not IsNull(Me.OpenArgs) then
Me.FormDefaultIDFieldName = Me.OpenArgs
Endif

The OpenArgs value is not going to do anything unless you manipulate it.

internet...@foobox.com

unread,
Jul 14, 2016, 8:46:53 AM7/14/16
to
Mike

You do not say why you prefer the use of ! instead of .

Interested

Jim

Mike P

unread,
Jul 14, 2016, 4:16:28 PM7/14/16
to
Jim,

I have researched this a few times and still do not have the definitive answer and so I am a bit reluctant to make this observation, but anyway, here goes.

Empirical evidence suggests that use of the ! (exclamation mark) refers to the name of the control in the form; use of the . (full-stop) refers to the field in the form's record source.
Most of the time it doesn't matter which version is used, especially if the control's name is the same as the control's data source.

But the full-stop version that refers to the control's data source will work regardless of the control's name or even when the form does not have a control bound to the data source. In the extreme case, I think it would be possible to refer to the fields in the form's record source even when there are no bound controls in the form. [Can't see any need for a bound form with no bound fields!].
So, I use the ! to refer to a control by name. I use the . to refer to the field in the form's record source if the form does not have a control bound to that field.

Also, I have had compilation errors which have been resolved by replacing the full-stop by an exclamation mark.

The last point. I think that the full-stop version will return Null if that is the value of the field, but the exclamation mark version will return "", empty string.

Please be sure to test this theory before basing any code on the statements made here.

More comments are welcome.

Mike P.

14/7/16

Patrick Finucane

unread,
Jul 14, 2016, 5:34:46 PM7/14/16
to
Here's a ink to describe the difference. http://datagnostics.com/dtips/bangdot.html

Joan Wild

unread,
Jul 15, 2016, 9:28:17 AM7/15/16
to

I have never gone wrong with 'bang if you named it; dot it you didn't'

Joan

internet...@foobox.com

unread,
Jul 15, 2016, 10:05:17 AM7/15/16
to
Thanks Mike for the explanation. I had a rough idea but this clarified matters. I always make the control name the same as the field name and the use dot notation. One of the main advantages of dot over bang is that intellisense works in the VBA code for the dot. It does not when using the bang. Therefore it is easier to make spelling mistakes when using bang and any error is not discovered until run time instead of compile time.

I conducted a small experiment with a field named Town for which I gave the control the name theTown. I was surprised that both me.Town and me.theTown both worked (and showed up in intellisense)

Jim

Joan Wild

unread,
Jul 15, 2016, 12:02:01 PM7/15/16
to
internet...@foobox.com wrote:

> Thanks Mike for the explanation. I had a rough idea but this
> clarified matters. I always make the control name the same as the
> field name and the use dot notation. One of the main advantages of
> dot over bang is that intellisense works in the VBA code for the dot.
> It does not when using the bang. Therefore it is easier to make
> spelling mistakes when using bang and any error is not discovered
> until run time instead of compile time.

<ctrl><space> will open the intellisense i.e. me! <ctrl><space>

Ulrich Möller

unread,
Jul 19, 2016, 7:21:56 AM7/19/16
to
Hi Mike,

out of microsoft's VBA Language Specification Documentation (Release:
April 30, 2014):

...
A /dictionary access expression/ is an alternate way to invoke an
object’s default member with a *String* parameter.
dictionary-access-expression = l-expression NO-WS "!" NO-WS
unrestricted-name
dictionary-access-expression =/ l-expression LINE-CONTINUATION "!" NO-WS
unrestricted-name
dictionary-access-expression =/ l-expression LINE-CONTINUATION "!"
LINE-CONTINUATION unrestricted-name

/Static semantics/. A dictionary access expression is invalid if the
declared type of <l-expression> is a type other than a specific class,
Object or Variant.
A dictionary access expression is syntactically translated into an index
expression with the same expression for <l-expression> and an argument
list with a single positional argument with a declared type of String
and a value equal to the name value of <unrestricted-name>.
...

Perhaps this may help.

Btw.:
All fields of a form's datasource are also accessible through the
controls collection, but they are not visible. It is not well
documented. So you can either use me!<fieldname> or
me.controls(<fieldname>). The datasource field is threaded as a hidden
control. This is very useful and needed if you want to manipulate the
cached field values of the form's datasource.

Because of this it is always a good idea to add a prefix to the control
names to clearly distinguish between controls and fields.

Ulrich
0 new messages