473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Seeking way to shorten this little code snippet...

MLH
Select Case Me.OpenArgs
Case "frmVehicleEntryForm"
Forms![frmVehicleEntryForm]![OwnerChooserBox].Requery
Case "frmEditTowedVehicleList"

Forms![frmEditTowedVehicleList]![OwnerChooserBox].Requery
End Select

Me.OpenArgs is the name of the calling form. There are only two forms
that open frmOwerEntryForm in which the above code resides. Can the
above snippet be shortened?
Feb 8 '06 #1
9 1681
This will work ...
Forms(Me.OpenArgs)!OwnerChooserBox.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*********@hotmail.com
http://amazecreations.com/datafast
"MLH" <CR**@NorthState.net> wrote ...
Select Case Me.OpenArgs
Case "frmVehicleEntryForm"
Forms![frmVehicleEntryForm]![OwnerChooserBox].Requery
Case "frmEditTowedVehicleList"

Forms![frmEditTowedVehicleList]![OwnerChooserBox].Requery
End Select

Me.OpenArgs is the name of the calling form. There are only two forms
that open frmOwerEntryForm 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**@NorthState.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=frmVehicleEntryForm"
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.Dictionary
object:
dim m_dict as Scripting.Dictionary
m_dict = ParseQueryString(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=frmVehicleEntryForm&Vehi cleID=123&DriverID=456"

-Tom.
Select Case Me.OpenArgs
Case "frmVehicleEntryForm"
Forms![frmVehicleEntryForm]![OwnerChooserBox].Requery
Case "frmEditTowedVehicleList"

Forms![frmEditTowedVehicleList]![OwnerChooserBox].Requery
End Select

Me.OpenArgs is the name of the calling form. There are only two forms
that open frmOwerEntryForm 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...@NorthState.net> wrote:
something ... I think


Feb 9 '06 #5
"MLH" <CR**@NorthState.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 "OwnerChooserBox" in your application, then
your existing code will find it.

For example, this code will search all open forms for controls
named "OwnerChooserBox" 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.Forms
For Each ctrl In obj.Controls
If ctrl.Name = "OwnerChooserBox" Then
obj.Requery
endif
Next ctrl
Next obj
End Sub
Feb 10 '06 #6
"Mark" <no****@thanksanyway.org> wrote:
For Each obj In Application.Forms
For Each ctrl In obj.Controls
If ctrl.Name = "OwnerChooserBox" Then
obj.Requery


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

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

For Each frm In Application.Forms
For Each ctrl In frm.Controls
If ctrl.Name = "OwnerChooserBox" 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**@NorthState.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****@thanksanyway.org> wrote:
"MLH" <CR**@NorthState.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.click()
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
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)...
42
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...
4
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...
2
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...
1
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. ...
7
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...
3
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...
13
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...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.