Unique random number on opening form for first time

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ragonz355
    New Member
    • Jun 2015
    • 5

    Unique random number on opening form for first time

    Have created a section in some code that opens a pre-existing form so that users can input new data. However I'm stuck at this point, basically there is a field in there called invoice number which they need to type in an invoice number (this can be anything, they just have to check it doesnt already exist)

    What I would like to happen is when they click on "Add New Enquiry" a unique invoice number is generated and put into the field for them, is that possible?

    Code to open the form is as follows

    Code:
    Private Sub cmdAddNewEnquiry_Click()
    On Error GoTo Err_cmdAddNewEnquiry_Click
    
        Dim stDocName As String
        Dim stLinkCriteria As String
    
        stDocName = "Job"
        
    
        DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd
        Forms!Job!STATUS.Value = "ENQUIRY"
    
        
    Exit_cmdAddNewEnquiry_Click:
        Exit Sub
    
    Err_cmdAddNewEnquiry_Click:
        MsgBox Err.Description
        Resume Exit_cmdAddNewEnquiry_Click
        
    End Sub
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    In the table design, set the field as an autonumber and set it to Random.

    Comment

    Working...