473,378 Members | 1,467 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,378 software developers and data experts.

VBA Syntax Question

A97, NT4.

I have a form with a command button which opens a second form. What's the
syntax to make the second form have the same record source as the first but
without hard-coding the form's name? The main form will be the only one
open when the button is clicked.

Background - I'm developing a custom filter form and want to use just one
filter form for many data sources, depending on which form I call it from.

Many thanks.
Keith.
Nov 13 '05 #1
7 1431
Keith <ke*********@AwayWithYerCrap.com> wrote:
What's the
syntax to make the second form have the same record source as the first
but without hard-coding the form's name?


Doen't matter, found it in the help:
Me.RecordSource = Forms(0).RecordSource
Nov 13 '05 #2
Grumpy Old Man wrote:
Keith <ke*********@AwayWithYerCrap.com> wrote:
What's the
syntax to make the second form have the same record source as the
first but without hard-coding the form's name?


Doen't matter, found it in the help:
Me.RecordSource = Forms(0).RecordSource


Forms(0) refers to the first form opened of all those currently open. If you
ever have more than one form opened then that will not be reliable.

Can't you just use the Me syntax?

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #3
"Rick Brandt" <ri*********@hotmail.com> wrote:
Forms(0) refers to the first form opened of all those currently open.
If you ever have more than one form opened then that will not be
reliable.

Can't you just use the Me syntax?


Other than the second form there'll only ever be one form opened at a time.
I can't use the Me keyword because I'm referring to Forms(0) from Forms(1).

Nov 13 '05 #4
Keith wrote:
"Rick Brandt" <ri*********@hotmail.com> wrote:
Forms(0) refers to the first form opened of all those currently open.
If you ever have more than one form opened then that will not be
reliable.

Can't you just use the Me syntax?


Other than the second form there'll only ever be one form opened at a
time. I can't use the Me keyword because I'm referring to Forms(0)
from Forms(1).


Another option would be to pass the name of the calling form in the OpenArgs
argument of the OpenForm method.

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #5
"Rick Brandt" <ri*********@hotmail.com> wrote:
Another option would be to pass the name of the calling form in the
OpenArgs argument of the OpenForm method.


Excellent idea, thanks I'll lokk into that.
Nov 13 '05 #6
Rick Brandt wrote:
Other than the second form there'll only ever be one form opened at a
time. I can't use the Me keyword because I'm referring to Forms(0)
from Forms(1).

Another option would be to pass the name of the calling form in the OpenArgs
argument of the OpenForm method.


Or what about soemthing like:

dim f as access.form
dim booCorrectForm as boolean

booCorrectForm = false

for each f in Access.forms

if f.name = "The_Name_of_the_form_you_Want" then

booCorrectForm = True

Exit For

end if

next

If booCorrectForm = true then

me.recordsource = f.recordsource

else

me.recordsource = whatever

end if
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Nov 13 '05 #7
rkc
Keith wrote:
A97, NT4.

I have a form with a command button which opens a second form. What's the
syntax to make the second form have the same record source as the first but
without hard-coding the form's name? The main form will be the only one
open when the button is clicked.

Background - I'm developing a custom filter form and want to use just one
filter form for many data sources, depending on which form I call it from.

Many thanks.
Keith.


From the calling form

Sub OpenFilterForm (frmName as string)
Dim f As Access.Form

DoCmd.OpenForm frmName
Set f = Forms(frmName)
f.RecordSource = Me.RecordSource

Set f = Nothing
End Sub
Nov 13 '05 #8

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

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
4
by: Aaron Walker | last post by:
Greetings, I'm attempting to write my first *real* template function that also deals with a map of strings to member function pointers that is making the syntax a little tricky to get right. ...
2
by: bor_kev | last post by:
Hi, First of all, i want to use the new managed class syntax and STL.NET under Microsoft Visual (C++) Studio 2005 Beta. I read in a Microsoft...
5
by: r.nikhilk | last post by:
Hi, Currently, we are porting C++ applications from 32 bit to 64 bit on AIX platform. (The current version of AIX is 5.3 and xlC verison is 8.0). We are able to compile the applications by...
3
by: astromog | last post by:
I have some significantly extended syntax for Python that I need to create a reference implementation for. My new syntax includes new keywords, statements and objects that are sort of like classes...
11
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();
8
by: Smithers | last post by:
Are there any important differences between the following two ways to convert to a type?... where 'important differences' means something more profound than a simple syntax preference of the...
2
by: berrylthird | last post by:
This question was inspired by scripting languages such as JavaScript. In JavaScript, I can access members of a class using array syntax as in the following example: var myInstance:myClass = new...
17
by: trose178 | last post by:
Good day all, I am working on a multi-select list box for a standard question checklist database and I am running into a syntax error in the code that I cannot seem to correct. I will also note...
6
by: Daniel | last post by:
I hope this question is OK for this list. I've downloaded Rpyc and placed it in my site packages dir. On some machines it works fine, on others not so much. Here is one error I get when I try...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.