Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / July 2007

Tip: Looking for answers? Try searching our database.

Send tblName variable to function

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Anand - 15 Jul 2007 08:10 GMT
Hello all,
I have function that finds the next record in a table. I use this function
to auto-generate the next record number (in a non-Autonumber field) in
several tables - although I have to have a separate function for each table.

The function uses the
dbs.OpenRecordSet ("tblTable1") code.
I would like to re-use this function by sending the Table Name as a variable
to the function - avoiding duplicity of the code. How do I do this?

Thanks in Advance
Anand
Allen Browne - 15 Jul 2007 08:45 GMT
This should do it:

Public Function NextNumber(strTable As String, strField As String, _
   Optional strCriteria As String) As Long
On Error Resume Next
   Dim lngMax As Long

   lngMax = Nz(DMax(strField, strTable, strCriteria), 0&)
   NextNumber = lngMax + 1&
End Function

Example for field ID in table Table1:
   ? NextNumber ("Table1", "ID")

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> Hello all,
> I have function that finds the next record in a table. I use this function
[quoted text clipped - 10 lines]
> Thanks in Advance
> Anand
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.