Results 1 to 4 of 4
  1. #1
    Symon is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Posts
    2

    Message Box to Display Number of Records that have just been created

    Hi All,

    I have a button that duplicates records 'X' amount of times based on a value in a text box.

    I need a message box to advise the user that they have created record number from - to

    Eg

    User creates 5 records - first record created has a auto number of 3200
    I need the message box to say 'you have just created records 3200 - 3204

    Is this possible?

    Here is the current code on the duplicate button

    Code:
    Private Sub AddRecord_Click()On Error GoTo AddRecord_Click_Err
    
    
    Dim x As Integer
            For x = 1 To (Me.Amount.Value - 1)
        
        DoCmd.RunCommand acCmdSelectRecord
            DoCmd.RunCommand acCmdCopy
            DoCmd.RunCommand acCmdRecordsGoToNew
            DoCmd.RunCommand acCmdSelectRecord
            DoCmd.RunCommand acCmdPaste
    
    
    Next x
    
    
    AddRecord_Click_Exit:
        Exit Sub
    
    
    AddRecord_Click_Err:
        MsgBox Error$
        Resume AddRecord_Click_Exit
    
    
    End Sub




    Thanks

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Maybe something like ...

    Code:
    Dim lngRecordStart as Long
    Dim lngRecordEnd as Long
    Dim x As Integer
    
            'For x = 1 To (Me.Amount.Value - 1)
            For x = 1 To (Me.Amount.Value)
        
        DoCmd.RunCommand acCmdSelectRecord
            DoCmd.RunCommand acCmdCopy
            DoCmd.RunCommand acCmdRecordsGoToNew
            DoCmd.RunCommand acCmdSelectRecord
            DoCmd.RunCommand acCmdPaste
    
    If x = 1 then
    lngRecordStart = Me![FieldName] 
    lngRecordEnd = Me![FieldName]
    else
    lngRecordEnd = Me![FieldName]
    end if
    
    Next x
    
    msgbox "You have just created records " & lngRecordStart & " - " & lngRecordEnd

  3. #3
    Symon is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Posts
    2
    Brilliant!! worked a treat with a little tweak...

    Many thanks.

    Code:
    Private Sub AddRecord_Click()Dim lngRecordStart As Long
    Dim lngRecordEnd As Long
    Dim x As Integer
    
    
            'For x = 1 To (Me.Amount.Value - 1)
            For x = 1 To (Me.Amount.Value - 1)
        
        DoCmd.RunCommand acCmdSelectRecord
            DoCmd.RunCommand acCmdCopy
            DoCmd.RunCommand acCmdRecordsGoToNew
            DoCmd.RunCommand acCmdSelectRecord
            DoCmd.RunCommand acCmdPaste
    
    
    If x = 1 Then
    lngRecordStart = (Me![Serial Number] - 1)
    lngRecordEnd = Me![Serial Number]
    Else
    lngRecordEnd = Me![Serial Number]
    End If
    
    
    Next x
    
    
    MsgBox "Creation of serial numbers " & lngRecordStart & " - " & lngRecordEnd
    End Sub

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    You bet. Just an FYI. The following four statements are identical. Each will iterate/loop 9 times.

    For x = 1 To (10 - 1)
    For x = 1 To (9)
    For x = 0 To (8)
    For x = 2 To (10)

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

Similar Threads

  1. Display XX number of records per page
    By cactuspete13 in forum Forms
    Replies: 11
    Last Post: 07-19-2014, 05:17 AM
  2. Replies: 2
    Last Post: 01-23-2014, 12:40 PM
  3. Replies: 8
    Last Post: 11-13-2012, 03:36 PM
  4. Replies: 6
    Last Post: 07-25-2011, 01:54 PM
  5. Code to display latest record number field created?
    By rowardHoark in forum Programming
    Replies: 1
    Last Post: 01-31-2011, 08:03 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