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

Passing fieldname to a subroutine

I have a form with a subform. In the subform I have several fields to
which I am assigning links to documents on the file server. I learned
(from this list :-) how to add the links. Because I will be executing
the code for four or five fields, I would like to have a generic
subroutine to pass the field name parameters to. I have searched and
tried many formats and syntaxes for this with no success.

Here are the principle lines from the routine that I wish to make more
general

lnkApplication = varFile & "#" & varFile ' puts the hyperlink in the
field.

lnkApplication.Visible = Not (IsNull(lnkApplication.Value)) ' only
shows the field on the form if it has a path in it

lnkApplication is the actual name of the field in a table called
tblFamilyMembers.

Please help me with the syntax to pass the fieldnames to a general
subroutine and to modify the lines above. Also, please let me know if
there are any additional lines of code needed to make it work.

Thanks,
Bernie

Jul 16 '06 #1
14 5341
haven't a clue what your example is on about, but the way to pass info
into a subroutine is pretty simple...

Sub MySubroutine(byval strFieldName as string)
dim strSQL as string
strSQL = "SELECT * FROM MyTable WHERE [" & strFieldName & "] =
'X';"
DBEngine(0)(0).Querydefs("qdfTemp").SQL = strSQL
End Sub

Does that help?

Jul 16 '06 #2
I'm guessing that lnkApplication is also the control on your form, if so
you can pass a reference to the control

e.g.

Sub wibble(MyControl as Ontrol)
' Stuff you've already got

With MyControl
.Value = varFile & "#" & varFile
.Visible = Not (IsNull(.Value))
End With
End Sub
And you'd call it with
Call wibble(Me.lnkApplication)


--

Terry Kreft
<bg********@gmail.comwrote in message
news:11*********************@m73g2000cwd.googlegro ups.com...
I have a form with a subform. In the subform I have several fields to
which I am assigning links to documents on the file server. I learned
(from this list :-) how to add the links. Because I will be executing
the code for four or five fields, I would like to have a generic
subroutine to pass the field name parameters to. I have searched and
tried many formats and syntaxes for this with no success.

Here are the principle lines from the routine that I wish to make more
general

lnkApplication = varFile & "#" & varFile ' puts the hyperlink in the
field.

lnkApplication.Visible = Not (IsNull(lnkApplication.Value)) ' only
shows the field on the form if it has a path in it

lnkApplication is the actual name of the field in a table called
tblFamilyMembers.

Please help me with the syntax to pass the fieldnames to a general
subroutine and to modify the lines above. Also, please let me know if
there are any additional lines of code needed to make it work.

Thanks,
Bernie

Jul 16 '06 #3
"Terry Kreft" <te*********@mps.co.ukwrote in
news:Ky********************@karoo.co.uk:
Sub wibble(MyControl as Ontrol)
' Stuff you've already got

With MyControl
.Value = varFile & "#" & varFile
.Visible = Not (IsNull(.Value))
End With
End Sub
The function declaration should be:

Sub wibble(MyControl as Control)

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Jul 16 '06 #4
Whoops, thanks David.

I hate this laptop.

--

Terry Kreft
"David W. Fenton" <XX*******@dfenton.com.invalidwrote in message
news:Xn**********************************@127.0.0. 1...
"Terry Kreft" <te*********@mps.co.ukwrote in
news:Ky********************@karoo.co.uk:
Sub wibble(MyControl as Ontrol)
' Stuff you've already got

With MyControl
.Value = varFile & "#" & varFile
.Visible = Not (IsNull(.Value))
End With
End Sub

The function declaration should be:

Sub wibble(MyControl as Control)

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/

Jul 16 '06 #5
I ended up passing the field name as a string and using

Me(strFieldName) = varFile & "#" & varFile

and later on

Me(strFieldName).Visible = Not (IsNull(Me(strFieldName).Value))

I'll try the code you have suggested because I think it will be simpler
than all of the code surrounding the lines I showed you.

I have been using straight Visual Basic for about 12 years and have
written VBA for Excel in the past. This is my first attempt at VBA
with Access and I find myself needing to lookup the syntax for
database-specific routines.

Is there a nice concise (not-written-by-MS) summary of how to write
syntax for Forms, Tables, Fields, etc.? My biggest hang up seems to be
choosing between ! and .

Thank you for your prompt and helpful responses above!

-Bernie

Jul 16 '06 #6
Is there a nice concise (not-written-by-MS) summary of how to write
syntax for Forms, Tables, Fields, etc.? My biggest hang up seems to be
choosing between ! and .
Simple Solution. Don't choose. I have used a bang (!) for years and
years.

Jul 16 '06 #7
bg********@gmail.com wrote in
news:11**********************@75g2000cwc.googlegro ups.com:
Is there a nice concise (not-written-by-MS) summary of how to
write syntax for Forms, Tables, Fields, etc.? My biggest hang up
seems to be choosing between ! and .
If it's a control or a field, use !. If it's a property or a method,
use .

Or, if you want to depend on undocumented wrapper properties created
for you behind the scenes in Access, you can use . too for controls
and fields in forms and reports. But you can't use it for fields in
a recordset.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Jul 17 '06 #8
* bg********@gmail.com:
I ended up passing the field name as a string and using

Me(strFieldName) = varFile & "#" & varFile

and later on

Me(strFieldName).Visible = Not (IsNull(Me(strFieldName).Value))

I'll try the code you have suggested because I think it will be simpler
than all of the code surrounding the lines I showed you.

I have been using straight Visual Basic for about 12 years and have
written VBA for Excel in the past. This is my first attempt at VBA
with Access and I find myself needing to lookup the syntax for
database-specific routines.

Is there a nice concise (not-written-by-MS) summary of how to write
syntax for Forms, Tables, Fields, etc.? My biggest hang up seems to be
choosing between ! and .

Thank you for your prompt and helpful responses above!

-Bernie
I'm not entirely certain this is what you had in mind, but this is what
I use:

http://www.mvps.org/access/forms/frm0031.htm

HTH
--
Randy Harris
tech at promail dot com
I'm pretty sure I know everything that I can remember.
Jul 17 '06 #9
Lyle Fairfield wrote:
Is there a nice concise (not-written-by-MS) summary of how to write
syntax for Forms, Tables, Fields, etc.? My biggest hang up seems to be
choosing between ! and .

Simple Solution. Don't choose. I have used a bang (!) for years and
years.
Correction:

I have not used a bang (!) for years and years.

Jul 17 '06 #10
>
http://www.mvps.org/access/forms/frm0031.htm
The reference is exactly what I was looking for. Thanks once again.
- Bernie

Jul 17 '06 #11
Lyle Fairfield wrote:
I have not used a bang (!) for years and years.
You don't say! Surely you emphasize statements! Emphasis requires bangs!

:-)
Jul 17 '06 #12

Larry Linson wrote:
Lyle Fairfield wrote:
I have not used a bang (!) for years and years.

You don't say! Surely you emphasize statements! Emphasis requires bangs!
Naah ... in these days of rtf, html etc, I use a small image of your
face, Larry, superimposed with the words, "44 Magnum".

Jul 17 '06 #13
"Lyle Fairfield" <ly***********@aim.comwrote in
news:11**********************@b28g2000cwb.googlegr oups.com:
Lyle Fairfield wrote:
Is there a nice concise (not-written-by-MS) summary of how to
write syntax for Forms, Tables, Fields, etc.? My biggest hang
up seems to be choosing between ! and .

Simple Solution. Don't choose. I have used a bang (!) for years
and years.

Correction:

I have not used a bang (!) for years and years.
Do ADO recordsets allow the use of the . for fields?

If so, that's another reason I'm glad I've never embarked on more
than just dabbling in ADO.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Jul 17 '06 #14
David W. Fenton wrote:
Do ADO recordsets allow the use of the . for fields?
Well I'm not sure what you mean. We can use any of these to get an
object pointer to a ADO field:

objField = objRecordset.Fields.Item("LastName")
objField = objRecordset.Fields("LastName")
objField = objRecordset.Fields.Item(1)
objField = objRecordset.Fields(1)

and in VBA it's likely we will need to use the SET operator as in
SET objField = objRecordset.Fields.Item("LastName")
but this is a peculiarity of VBA and not ADO.

There are many ways to retrieve the value of an ADO field:

Dim objRecordset As ADODB.Recordset
Set objRecordset = CurrentProject.Connection.Execute("SELECT * FROM
Employees")
Debug.Print objRecordset.Fields("LastName")
Debug.Print objRecordset.Fields("LastName").Value
Debug.Print objRecordset.Fields(1)
Debug.Print objRecordset.Fields(1).Value
Debug.Print objRecordset.Collect("LastName")
Debug.Print objRecordset!LastName

I frequently use
..Collect("LastName")
TTBOMK this is the fastest of all showed above.

But Dimitri Furman has pointed out that this is faster (tested by
several in a thread some years ago):
Dim objRecordset As ADODB.Recordset
Dim objField As ADODB.Field
Set objRecordset = CurrentProject.Connection.Execute("SELECT * FROM
Employees")
Set objField = objRecordset.Fields("LastName")
Debug.Print objField.Value
and I use it if there are going to be enough uses of the objField
pointer to offset the times and resources needed for its creation.

I never use
objRecordset!LastName
I never have to choose; my code is consistent;
[!] like [.Collect] short circuits and obscures the Field(Index).Value
OOP reference
TTBOMR Intellisense does not help with !
MS wizards, help files and kb articles write some bizarre and lengthy
combinations of [.] and [!]. I think these are confusing to many.

TTBOMK all of the above (with the exception of loading the recordset)
is identical in DAO.

Jul 18 '06 #15

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

Similar topics

6
by: Adrian | last post by:
I am trying to pass the address of a C++ function into a Fortran routine to enable the Fortran routine to call this C++ function. I have to do it this way as our build process does not allow...
1
by: Sam | last post by:
Hello all I have a two dimensional array (the dimensions are not known) that needs to be passed to fortran from c++, allocate the dimensions of the array in fortran code, do some filling up of...
3
by: Scott | last post by:
What is the proper syntax for sending an argument from a form contol to a subroutine in a module? For instance, from a textbox on a form I call a module subroutine from the textbox's OnUpdate...
7
by: Richard Grant | last post by:
Hi. In c/C++ i can pass the address of a subroutine to another subroutine as an actual parameter How do I do that in VB .NET What should be the syntax for a parameter to receive the address of a...
3
by: Stephen Travis | last post by:
I'm trying to write a subroutine that will fill an array of some type with several objects of that type. The subroutine works fine if I directly reference the array but if I pass the array as an...
2
by: Mark Drummond | last post by:
Hi all. I've been using Perl for many years now, but I am a "use it and learn it as you need it" type. I having some trouble passing a list to the "search" subroutine from Net::LDAP. I am trying...
2
by: mj.redfox.mj | last post by:
Hi, Pretty basic question, apologies but being a bit of a newbie I still don't know the answer to this kind of thing! I have a repeater which, upon databind calls a subroutine, as below: ...
2
by: luis | last post by:
I'm using ctypes to call a fortran dll from python. I have no problems passing integer and double arryas, but I have an error with str arrys. For example: ..... StringVector = c_char_p *...
18
by: Carl Forsman | last post by:
there are 2 ways to return a value from a function ==================== 1) passing a reference as parameter - the following will return time void Table::Get(char* FieldName, *SYSTEMTIME time) {...
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.