473,698 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question of syntax

Some time ago Steve Jorgenson, (I think it was he), wrote of possible
problems using the intellisense-friendly "Form_" syntax to refer to forms
and their controls. At the time I responded that I'd never seen any
problems - which was true until today.

Using Access XP on WinXP Pro with all service packs.

My code checks to see if a form, "frmMain", is dirty. So my options are::

a) If Form_frmMain.Di rty Then
b) If Forms("frmMain" ).Dirty Then
c) If Forms![frmMain].Dirty Then.

For some reason, using option a) above causes one of my combo boxes to lose
it's records. The combo box is populated, using a callback function, from a
sql server stored procedure. Several other combo boxes are unaffected. If I
requery the combo box I get my records back. The problem occurs whether or
not the form is actually dirty - simply the reference to Form_frmMain
apparently vaporizes the records.

At the risk of starting a syntax flame war I just thought I'd mention this
here and see if anyone has any comments.

Other than "well don't use a) then" :-).
Nov 13 '05 #1
5 1934
That is quite interesting!

one question:

Any possibility that you have multiplate copies, or this is used in a
sub-form?

You see, if you direct reference the form object, and multiplate copies
exists (such as the INSTANT you use the form as a sub-form, the ms-access
will actually refer to the first instance of that sub-form..but after that,
it can't know!

So, in the case of a sub-form, or multiple instances of a form allowed, then
ms-access gets confused as to what form_Name is when more then one copy is
loaded.

Best not to do that!

If you don't have more then one instance loaded, and you are not using this
as a sub-form..then I am at a loss, but as always, using the base object can
cause problems...
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl************* ****@msn.com
http://www.attcanada.net/~kallal.msn
Nov 13 '05 #2
John,
The obvious difference is that (b) and (c) refer to form instances in the
forms collection whereas (a) will create an instance of frmMain if one
doesn't exist.

Try running the following

Function wibble()
Debug.Print "Forms Count = " & Forms.Count
Form_frmMain.Wi dth = 200
Debug.Print "Forms Count = " & Forms.Count
Set Form_frmMain = Nothing
Debug.Print "Forms Count = " & Forms.Count
End Function

output
Forms Count = 0
Forms Count = 1
Forms Count = 0

interestingly replacing
Form_frmMain.Wi dth = 200

with
Form_frmMain.Di rty = False

generates an error but the form instance is still created.

IOW using the Form_frmMain is not a good idea, it's a bit like using the New
keyword when declaring an object variable and we all know that's bad don't
we ? <g>

--
Terry Kreft
MVP Microsoft Access
"John Winterbottom" <as******@hotma il.com> wrote in message
news:2k******** ****@uni-berlin.de...
Some time ago Steve Jorgenson, (I think it was he), wrote of possible
problems using the intellisense-friendly "Form_" syntax to refer to forms
and their controls. At the time I responded that I'd never seen any
problems - which was true until today.

Using Access XP on WinXP Pro with all service packs.

My code checks to see if a form, "frmMain", is dirty. So my options are::

a) If Form_frmMain.Di rty Then
b) If Forms("frmMain" ).Dirty Then
c) If Forms![frmMain].Dirty Then.

For some reason, using option a) above causes one of my combo boxes to lose it's records. The combo box is populated, using a callback function, from a sql server stored procedure. Several other combo boxes are unaffected. If I requery the combo box I get my records back. The problem occurs whether or
not the form is actually dirty - simply the reference to Form_frmMain
apparently vaporizes the records.

At the risk of starting a syntax flame war I just thought I'd mention this
here and see if anyone has any comments.

Other than "well don't use a) then" :-).

Nov 13 '05 #3
"Terry Kreft" <te*********@mp s.co.uk> wrote in message
news:0W******** ************@ka roo.co.uk...
John,
The obvious difference is that (b) and (c) refer to form instances in the
forms collection whereas (a) will create an instance of frmMain if one
doesn't exist.

Try running the following

Function wibble()
Debug.Print "Forms Count = " & Forms.Count
Form_frmMain.Wi dth = 200
Debug.Print "Forms Count = " & Forms.Count
Set Form_frmMain = Nothing
Debug.Print "Forms Count = " & Forms.Count
End Function

output
Forms Count = 0
Forms Count = 1
Forms Count = 0 interestingly replacing
Form_frmMain.Wi dth = 200

with
Form_frmMain.Di rty = False

generates an error but the form instance is still created.

Hi Terry, thanks for the reply. I understand a bit more about this now - and
about what is happening behind the scenes, This last point is interesting; I
changed my code to

If Form_frmMain.Wi dth > 0

and, surprise surprise, no problems. So something is up with the combination
of syntax a) and the forms' Dirty property.

IOW using the Form_frmMain is not a good idea, it's a bit like using the New keyword when declaring an object variable and we all know that's bad don't
we ? <g>


I started using the "Form_" syntax some time ago, primarily because it
allows you to take advantage of intellisense. It seems this wasn't such a
good move after all! Thanks again.



Nov 13 '05 #4
"Albert D. Kallal" <Pl************ *******@msn.com > wrote in message
news:SJ8Fc.9656 14$oR5.537248@p d7tw3no...
That is quite interesting!

one question:

Any possibility that you have multiplate copies, or this is used in a
sub-form?

You see, if you direct reference the form object, and multiplate copies
exists (such as the INSTANT you use the form as a sub-form, the ms-access
will actually refer to the first instance of that sub-form..but after that, it can't know!

So, in the case of a sub-form, or multiple instances of a form allowed, then ms-access gets confused as to what form_Name is when more then one copy is
loaded.

Best not to do that!

If you don't have more then one instance loaded, and you are not using this as a sub-form..then I am at a loss, but as always, using the base object can cause problems...


Hi Albert, thanks for the reply. No, no multiple copies open - and it's not
a subform. As I said to Terry, it seems that accessing the Dirty property is
what is causing the problem. Other form props, like Width, are OK. Well,
I've spent enough time on this now. I will change my practices and move on.


Nov 13 '05 #5
John,
If you decalre a variable of type of the form you still get intellisense but
without the irritating creation of an unexpected instance.

e.g
Function wibble2()
Dim fM As Form_frmMain

' If the following line isn't included you get the dreaded error
' 91 - Object variable or With block variable not set
Set fM = New Form_frmMain

Debug.Print "Forms Count = " & Forms.Count
fM.Width = 200
Debug.Print "Forms Count = " & Forms.Count
Set fM = Nothing
Debug.Print "Forms Count = " & Forms.Count
End Function

--
Terry Kreft
MVP Microsoft Access
"John Winterbottom" <as******@hotma il.com> wrote in message
news:2k******** ****@uni-berlin.de...
"Terry Kreft" <te*********@mp s.co.uk> wrote in message
news:0W******** ************@ka roo.co.uk...
John,
The obvious difference is that (b) and (c) refer to form instances in the forms collection whereas (a) will create an instance of frmMain if one
doesn't exist.

Try running the following

Function wibble()
Debug.Print "Forms Count = " & Forms.Count
Form_frmMain.Wi dth = 200
Debug.Print "Forms Count = " & Forms.Count
Set Form_frmMain = Nothing
Debug.Print "Forms Count = " & Forms.Count
End Function

output
Forms Count = 0
Forms Count = 1
Forms Count = 0
interestingly replacing
Form_frmMain.Wi dth = 200

with
Form_frmMain.Di rty = False

generates an error but the form instance is still created.

Hi Terry, thanks for the reply. I understand a bit more about this now -

and about what is happening behind the scenes, This last point is interesting; I changed my code to

If Form_frmMain.Wi dth > 0

and, surprise surprise, no problems. So something is up with the combination of syntax a) and the forms' Dirty property.

IOW using the Form_frmMain is not a good idea, it's a bit like using the

New
keyword when declaring an object variable and we all know that's bad don't we ? <g>


I started using the "Form_" syntax some time ago, primarily because it
allows you to take advantage of intellisense. It seems this wasn't such a
good move after all! Thanks again.




Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
6462
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I COULD be wrong... :) I've tried the access group...twice...and all I get is "Access doesn't like ".", which I know, or that my query names are too long, as there's a limit to the length of the SQL statement(s). But this works when I don't try to...
9
1250
by: Hasani \(remove nospam from address\) | last post by:
I was reading a ppt ( http://www.gotdotnet.com/team/pdc/4064/tls310.ppt ) and came aross this statement. "Users can leverage a destructor. The C++ compiler generates all the Dispose code automatically, including chaining calls to Dispose. (There is no Dispose pattern)" but Dispose can thrown an exception. Is the exception supressed?
6
2289
by: Ludwig | last post by:
Hi, i'm using the regular expression \b\w to find the beginning of a word, in my C# application. If the word is 'public', for example, it works. However, if the word is '<public', it does not work: it seems that < is not a valid character, so the beginning of the word starts at theletter 'p' instead of '<'. Because I'm not an expert in regular expressions, maybe someone of you guys can help me? I need the correct regex to find the...
5
1753
by: Steve Schlesinger | last post by:
Suppose you have class A {}; class B {} template<class T> void SomeFcn( T t ) {…}; A a; B b;
11
5209
by: deppy_3 | last post by:
Hi! The syntax of fputs() is similar with the syntax of fgets(); For example if we have:fgets(str,maxlen,stdin) which is the syntax of the fputs();
0
2074
by: | last post by:
I have a question about spawning and displaying subordinate list controls within a list control. I'm also interested in feedback about the design of my search application. Lots of code is at the end of this message, but I will start with an overview of the problem. I've made a content management solution for my work with a decently structured relational database system. The CMS stores articles. The CMS also stores related items --...
5
1206
by: Scott | last post by:
I'm sorry if most of my question's seem "petty", but as I've said before, I need to know the petty just because I need to know. This question is more along the lines of just having you guys either agree or disgree with me, and if disagreeing to give the reasoning behind it, to further my understanding of lists. Am I safe in assuming that if the list your building contains number's it will be written as follows:
8
1818
by: boki_pfc | last post by:
Hi Everybody, I am looking for an advice on following: I have that "pleasure" of reading C++ codes that have been written by person(s) that have not attended the same C++ classes that I did or have not read the same C++ books that I have read. This kind of people has written some parts of the code that use notations that I am not familiar with (and that probably also includes also 50 % of other C ++ programmers). While everybody who...
48
1505
by: teapot | last post by:
If I compile this program int main(void) { return 0; // foo bar baz } with "lc -A -ansi89 foo.c"
5
1791
by: =?Utf-8?B?SmVzc2ljYQ==?= | last post by:
Hello, I have a pInvoke question. This is the C function that is exported from one of the C dll, extern __declspec(dllexport) IM_RET_CODE ST_import (IM_MODE mode, char *filename, ST_TYPES **st_type, ST_ERROR **st_error);
0
8668
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9152
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8855
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7708
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4358
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2320
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1995
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.