473,657 Members | 2,678 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Seeking way to shorten this little code snippet...

MLH
Select Case Me.OpenArgs
Case "frmVehicleEntr yForm"
Forms![frmVehicleEntry Form]![OwnerChooserBox].Requery
Case "frmEditTowedVe hicleList"

Forms![frmEditTowedVeh icleList]![OwnerChooserBox].Requery
End Select

Me.OpenArgs is the name of the calling form. There are only two forms
that open frmOwerEntryFor m in which the above code resides. Can the
above snippet be shortened?
Feb 8 '06 #1
9 1692
This will work ...
Forms(Me.OpenAr gs)!OwnerChoose rBox.Requery

Provided that OpenArgs is never empty and that the form it references
always has that particular control. You might add another call to see
if the form exists before doing the requery.
--

Danny J. Lesandrini
dl*********@hot mail.com
http://amazecreations.com/datafast
"MLH" <CR**@NorthStat e.net> wrote ...
Select Case Me.OpenArgs
Case "frmVehicleEntr yForm"
Forms![frmVehicleEntry Form]![OwnerChooserBox].Requery
Case "frmEditTowedVe hicleList"

Forms![frmEditTowedVeh icleList]![OwnerChooserBox].Requery
End Select

Me.OpenArgs is the name of the calling form. There are only two forms
that open frmOwerEntryFor m in which the above code resides. Can the
above snippet be shortened?

Feb 8 '06 #2
MLH
Alright. Everybody loves a good one-liner.
Thx.
Feb 8 '06 #3
On Mon, 27 Mar 2006 12:56:51 -0500, MLH <CR**@NorthStat e.net> wrote:

Danny had a good suggestion. I'm focussing on the use of OpenArgs to
pass in a form name. I prefer to do that a bit differently. I use a
querystring-like string for OpenArgs:
Docmd.OpenForm "someform",,,,, ,"FormName=frmV ehicleEntryForm "
The beauty is that the OpenArgs string becomes self-documenting, and
that we are re-using a format that everyone is already familiar with.

Then in the receiving form, I parse OpenArgs using a function that I
wrote once to parse any querystring into a Scripting.Dicti onary
object:
dim m_dict as Scripting.Dicti onary
m_dict = ParseQueryStrin g(Me.OpenArgs)
The beauty is that OpenArgs becomes very flexible; I can add more
arguments at any time and will not get confused about what's what:
Docmd.OpenForm
"someform",,,,, ,"FormName=frmV ehicleEntryForm &VehicleID=123& DriverID=456"

-Tom.
Select Case Me.OpenArgs
Case "frmVehicleEntr yForm"
Forms![frmVehicleEntry Form]![OwnerChooserBox].Requery
Case "frmEditTowedVe hicleList"

Forms![frmEditTowedVeh icleList]![OwnerChooserBox].Requery
End Select

Me.OpenArgs is the name of the calling form. There are only two forms
that open frmOwerEntryFor m in which the above code resides. Can the
above snippet be shortened?


Feb 9 '06 #4
Que sera, sera
Whatever will be, will be
The future's not ours to see
Que sera, sera
What will be, will be

On Mon, 27 Mar 2006 12:56:51 -0500, MLH <C...@NorthStat e.net> wrote:
something ... I think


Feb 9 '06 #5
"MLH" <CR**@NorthStat e.net> wrote:
Can the above snippet be shortened?


I'm a big fan of letting VBA go out and find relevant objects at runtime.
It doesn't necessarily result in shorter code (although it will if you are
replacing a _lengthy_ set of conditional statements.) The beauty of it
is that if you are consistent in your naming standards for the objects
that you want to manipulate, then this will catch all of them. And if you
decide to put another "OwnerChooserBo x" in your application, then
your existing code will find it.

For example, this code will search all open forms for controls
named "OwnerChooserBo x" and execute the Requery method
for each control. For added safety you could validate the control
type as well.

Sub do_requeries()
Dim obj As Form
Dim ctrl As Control

For Each obj In Application.For ms
For Each ctrl In obj.Controls
If ctrl.Name = "OwnerChooserBo x" Then
obj.Requery
endif
Next ctrl
Next obj
End Sub
Feb 10 '06 #6
"Mark" <no****@thanksa nyway.org> wrote:
For Each obj In Application.For ms
For Each ctrl In obj.Controls
If ctrl.Name = "OwnerChooserBo x" Then
obj.Requery


Make that "ctrl.Reque ry" of course. Shame on me.
Try this instead:

Sub do_requeries()
Dim frm As Form
Dim ctrl As Control

For Each frm In Application.For ms
For Each ctrl In frm.Controls
If ctrl.Name = "OwnerChooserBo x" Then
ctrl.Requery
endif
Next ctrl
Next frm
End Sub
Feb 10 '06 #7
MLH
That's pretty neat. I like it.
Feb 10 '06 #8
"MLH" <CR**@NorthStat e.net> wrote:
That's pretty neat. I like it.


It's one of several approaches. I like it, but it does
impose a control naming convention in order for it
to work. In your case, your naming convention is
already in place, so this approach probably makes
sense for you.

Good luck
-Mark
Feb 10 '06 #9
"Mark" <no****@thanksa nyway.org> wrote:
"MLH" <CR**@NorthStat e.net> wrote:
That's pretty neat. I like it.


It's one of several approaches. I like it, but it does
impose a control naming convention in order for it
to work.


And of course, you wouldn't want to use this code
inside a recursive loop. Execution time for my code
sample probably won't be noticeable if it runs in
response to a user input. Example:

sub cmdRequery.clic k()
do_requeries()
end sub

That would be fine. But try this:

dim iCnt as integer
for iCnt = 1 to 10000
do_requeries()
loop

and your users will enter a House of Pain.
Feb 10 '06 #10

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

Similar topics

3
2634
by: Sean | last post by:
I am seeking an online PHP application that will do the following: 1.A web visitor can submit an online application. 2.The application gets stored in MYSQL as a file. (Like a support ticket) 3.The website owner can then retrieve the "submission" and add notes. 4.Then when the file is considered "finished" or no longer need - it can be erased. I have seen several different types of this application used as a Help
42
9690
by: Steven O. | last post by:
I am seeking some kind of tool that I can use for GUI prototyping. I know how to use Visual Basic, but since a lot of software is being coded in Java or C++, I'd like to learn a Java or C++ -based tool. Back when I took my Java and C++ classes (two or three years ago), the available tools -- at least the ones I could find -- were still not as easy, not as "drag-and-drop", as Visual Basic. Has that changed? Is there some software out...
4
1509
by: B.J. | last post by:
Hi, Is there any way how I can shorten following code ? try {...} catch(FormatException) {SAME CODE IN ALL CATCH BLOCKS} catch(OverflowException) {SAME CODE IN ALL CATCH BLOCKS} E.g. to this ...
2
1224
by: MLH | last post by:
I want to read more about the microsoft user interface specification for windows applications. I know there are standards that have been developed and I want to gain a little more expertise in the topic. Seeking Web Resources Recommendations?
1
1750
by: Chris Austin | last post by:
A co-worker asked me today what would happen if Session.Add() method was called multiple times with the same key. My first thought was that it would throw some sort of duplicate key exception. Thinking about it some more, the only thing it really does is implement ICollection and possibly IDictionary so the implementation could be anything so I looked into a bit further. Documentation didn't say anything about the Add() methods besides...
7
13372
by: semedao | last post by:
Hi, I am using cryptostream on both sides on tcp connection that pass data. I am also use asyc socket , so , the data that recieved in the callback method not always have the length of the buffer I sent. for ex I want to send 10000 bytes I can get it in 10 times of 1000 bytes each. so , I need to know when I complete the receiving , I want to write inside cryptostream and check the position compare it to the length I already know I...
3
1996
by: Ronald S. Cook | last post by:
I'm developing a Windows application that will have an ListBar like in Outlook. When the user clicks on a ListBar item, I would like to load the associated User Control. The below code works fine, but I'm looking for something more dynamic (since we'll have dozens if not hundreds of user listbar items/user controls). private void ulbListBar_ItemSelected(object sender, Infragistics.Win.UltraWinListBar.ItemEventArgs e) {...
13
2307
by: frk.won | last post by:
I am interested in learning how to use the VS 2005 code snippets. However, I wish to know what are the best ways to source control the code snippets? Are there any source safe/subversion add-ons for this purpose? If not, any urls which demonstrates code snippets management?
1
3521
by: treeguy | last post by:
I am not a developer but my site has long URL strings that have problem getting crawled. I understand Google now will crawl past the + but does not like the long strings. I tried URL rewrite and it did not work for me. Seem like there would be command in the asp to tell ti to shorten the string here is one of mine. http://www.landincorporated.com/Preview.aspx?pID=81e23cf6-0303-40a7-ba66-367fa393e125 at http:// www.landincorporated.com ...
0
8403
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
8316
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8610
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
7345
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
5636
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4168
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...
0
4327
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2735
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
1967
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.