Identify fields in subroutine call

  • Thread starter Thread starter news2
  • Start date Start date
N

news2

I wish to perform the same operation using each of several fields in the
same database. A common subroutine would seem to be the best approach.

I don't know how to pass the identification of the field to the subroutine.

Something like:

call subroutinex <field_identifier>
------------..

private subroutinex (<field_identifier> as <I don't know>
dim field_identifier as <I don't know>

<open the database containing the field>
..
<perform actions based on the contents of that field>..

end sub
 
That may depend on where you wish to call the function from.

If you are working in a form (or a report) and wish to call the function for
one of the controls, you could use something like:

Call YourFunction(Me!YourControlName)

--
Regards

Jeff Boyce
www.InformationFutures.net

Microsoft Office/Access MVP


Microsoft IT Academy Program Mentor
http://microsoftitacademy.com/
 
I'd like the subroutine to open a table (or query) and search the records
for particlular contents in the requested field and when matched do other
processing on that record.

Dick
 
I'd like the subroutine to open a table (or query) and search the records
for particlular contents in the requested field and when matched do other
processing on that record.

Dick

it's not clear what you mean by particular contents, and it's not clear what
record your looking when you say requested field. by requested field you
mean the primary key?

Perhaps you intend to pass the primary key to locate the record. And then
use a few of additonal field values you passed to update the data?

I would suggest then that you pass the field names as simple strings, as
that's what SQL uses most the time anyway.

eg:


Public Sub (pk as string, pKValue as string, strTablename as string)

you not made it clear how many parameters (fields) you plan to pass to this
sub. , but we'll just assume the above two for now.


dim strSql as string
dim rstData as dao.recordSet


strSql = "select " & pk & " from " & strTablename & _
" where " & pk & " = " & pKValue

set rstData = currentdb.OpenRecordSet(strSql)

if rstData.RecordCount > 0 then
' data exists...edit, do whatever..
rstData.edit.
rstData("companyanme") = somevalue
....etc
else
' reocrd not found...perahps add it?
rstData.Addnew
end

rstdata.Update

so the above snippet of code should give you some ideas. Also, depending on
your task you wish to accomplish you might be better off to use SQL update
commands than that of using a record set like above (it really just depends
on what you're trying to accomplish).
 
Back
Top