Results 1 to 3 of 3
  1. #1
    manissinha is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    Jul 2017
    Posts
    21

    How to show last record number from access tabel to excel userform in label or textbox

    hi



    How to show last record number from access table to excel userform in label or textbox and also show last record number when excel UserForm Initialize.

    thanks

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    get the max id from the query and ado connection

    Code:
    Dim conn As ADODB.Connection
    Dim rst As ADODB.Recordset
    Dim cmd As New ADODB.Command
    Dim sSql As String
    
    Set conn = CreateObject("ADODB.Connection")
    conn.Provider = "Microsoft.Jet.OLEDB.4.0"
    conn.Open "c:/webdata/northwind.mdb"
    
    sSql = "SELECT Max(tNames.ClientID) AS MaxOfClientID FROM tNames;"
    
    With cmd
         .CommandText = sSql                'Name of the stored procedure
         .CommandType = adCmdText
         .ActiveConnection = conn.ConnectionString
     End With
    
    Set rst = cmd.Execute
    
       'fill in the value here
    txtBox = rst.Fields("MaxOfClientID").Value
    
    conn.Close
    Set rst = Nothing
    Set conn = Nothing

  3. #3
    manissinha is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    Jul 2017
    Posts
    21
    thanks a lot ranman256 ......

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 17
    Last Post: 07-21-2017, 01:24 AM
  2. Access report change label value based on page number
    By system243trd in forum Programming
    Replies: 1
    Last Post: 05-24-2016, 08:54 AM
  3. How to show next available record number
    By gebmiller1984 in forum Forms
    Replies: 1
    Last Post: 02-04-2015, 01:23 PM
  4. Replies: 3
    Last Post: 01-14-2014, 04:17 PM
  5. Replies: 3
    Last Post: 06-17-2012, 11:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums