Code problem relating to custom string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • damonreid
    Recognized Expert New Member
    • Jul 2007
    • 114

    Code problem relating to custom string

    I have a drop down list that takes a "Stock Type" and then assigns a new code based on that stock type to a field called "Stock ID".
    The Idea is to have XXX-0001 as the first ID and XXX-0002 as the second. Then you could have a BXA-001 as well. I have done this several times before but now I get an error when I try.

    Run-Time Error '2001'
    You Canceled the previous operation.

    Code is show here.
    I have a query "SectionCodeQue ry" that filters by Stock Type based on the same form.

    [code=vb]Private Sub Stock_Type_Afte rUpdate()
    Dim strProdCode As String
    Dim strCriteria As String

    If Me.NewRecord Then
    strProdCode = Me.Stock_Type.V alue
    'Increment the lngNum field by One, if field is Null, set as 0 then add 1
    Me!CodeNumber = Nz(DMax("Right( strID,4)", "SectionCodeQue ry"), 0) + 1
    'Customize the ID then attach the incremented
    Me!Stock_ID = Me.Stock_Type.V alue & "-" & Format(Me!IngNu m, "0000")
    Else
    Me!Stock_ID = Me!Stock_ID
    End If

    End Sub[/code]
  • FishVal
    Recognized Expert Specialist
    • Jun 2007
    • 2656

    #2
    Originally posted by damonreid
    I have a drop down list that takes a "Stock Type" and then assigns a new code based on that stock type to a field called "Stock ID".
    The Idea is to have XXX-0001 as the first ID and XXX-0002 as the second. Then you could have a BXA-001 as well. I have done this several times before but now I get an error when I try.

    Run-Time Error '2001'
    You Canceled the previous operation.

    Code is show here.
    I have a query "SectionCodeQue ry" that filters by Stock Type based on the same form.

    [code=vb]Private Sub Stock_Type_Afte rUpdate()
    Dim strProdCode As String
    Dim strCriteria As String

    If Me.NewRecord Then
    strProdCode = Me.Stock_Type.V alue
    'Increment the lngNum field by One, if field is Null, set as 0 then add 1
    Me!CodeNumber = Nz(DMax("Right( strID,4)", "SectionCodeQue ry"), 0) + 1
    'Customize the ID then attach the incremented
    Me!Stock_ID = Me.Stock_Type.V alue & "-" & Format(Me!IngNu m, "0000")
    Else
    Me!Stock_ID = Me!Stock_ID
    End If

    End Sub[/code]
    Hi, there.

    Your code is not clear.
    Is Me!CodeNumber the same as Me!lngNum?
    And what does it mean - Me!Stock_ID = Me!Stock_ID
    And I can only guess what is happening behind the scenes in "SectionCodeQue ry", but are you sure it filters records where strID starts from Me.Stock_Type?

    Comment

    Working...