Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1132
  • Last Modified:

Use of DMax in Excel not working./

Hi Team,

the given below code is not working form me.  Can you please help.

Private Sub RecTimeAddition()
    'Database Declariation
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim dblDocID As Double

    'Database Connection
    Set db = OpenDatabase("DatebasePath.mdb")
    Set rs = db.OpenRecordset("tblRecevied", dbOpenTable)
    
    'Get the Doc ID
    dblDocID = DMax("rs.[tblRecevied].[DocID]", "rs.[tblRecevied]")

End Sub

Open in new window

0
Sandesh555
Asked:
Sandesh555
  • 2
1 Solution
 
jpaulinoCommented:
Try this way:


dblDocID = DMax(rs.[tblRecevied].[DocID], rs.[tblRecevied])


Note: That way you are not getting the results from the recordset for the DMAX function but using that as strings
0
 
IrogSintaCommented:
Try:
Set db = OpenDatabase("DatebasePath.mdb")
dblDocID  = db.OpenRecordset ("Select Max(DocID) From tblReceived").Field(0)

or

Set db = OpenDatabase("DatebasePath.mdb")
Set rs = db.OpenRecordset ("Select Max(DocID) As MaxID From tblReceived")
dblDocID  = rs!MaxID
0
 
Martin LissRetired ProgrammerCommented:
As I understand it (I've never used it) DMAX works on a "database" consisting of a range of cells in Excel, rather than an Access database. Here's an example.
0
 
IrogSintaCommented:
Looking at the code I gave you and the one you provided, I see you have tblReceived spelled as tblRecevied, so you need to adjust accordingly.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now