Results 1 to 7 of 7
  1. #1
    melhado
    Guest

    Automatic incrementors, part 2 (Access 2K SR-1)

    Below is posted code I am using to increment a number which is then used as part of a concatenated value for display only. I used this code on a test form I did -- and got help on it here, and it worked fine. The test form was a form/subform, with the criteria on the main form, and the value to be incremented on the subform. Once I got it working, I then continued to build the real form, pretty much the same idea, same criteria, even the same field names on the forms, just different tables, and a little more complexity.

    I have commented the code extensively for this post, so you can see what I am doing with detail. The problems I am coming across here that did not happen in the test are on the line (in red). I am getting a <font color=red>runtime error 2448, Can't assign a value to this object</font color=red>. I did not get that in the test form -- intS_num is still a text box (here it is hidden, on the test it was not), still bound to an Integer data type field. Why can't I assign a value to it? Or is there another issue I am overlooking?

    I tried to Dim it and it got rid of the run time error, but didn't do anything! I checked the field names in the table, the control names and all is OK. Any ideas?

    Thanks

    'dave

    <font color=blue>
    Dim intNum As Integer
    Dim strWhere As String
    Dim strNum As String
    <font color=448800>'Dim intS_Num As Integer

    '"frmL60Tin" is the main form to which this
    'subform is attached. It contains 2 of
    'the 3 linking fields forming the ID which forms
    'the criteria forDmax to look at for incrementing.</font color=448800>
    strWhere = "Bill_Num ='" & Forms!frmL60Tin!txtBill_Num & _
    "' AND Bill_Half ='" & _
    Forms!frmL60Tin!txtBill_Half & "'"

    <font color=448800>'test for new record if used onCurrent
    'If Me.NewRecord = True Then

    'Sets variable to be used for incrementer.
    'Looks for highest value in the table field S_Num
    'that fits the criteria stated above.</font color=448800>
    intNum = Nz(DMax("S_Num", "tblTin", strWhere), 0)

    <font color=448800>'sets value of hidden text box, intS_Num (bound to
    'S_Num field,Integer data type) on this
    'subform to the counter value</font color=448800>
    <font color=red>intS_Num = intNum + 1</font color=red>

    <font color=448800>'pads leading 0 if needed.
    'Done for display of concatenated value
    'which must show a 2 character value for this part.</font color=448800>
    If intS_Num < 10 Then
    strNum = "0" & intS_Num
    Else
    strNum = CStr(intS_Num)
    End If

    'End If

    End Sub

  2. #2
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Automatic incrementors, part 2 (Access 2K SR-1)

    You will get this error if textbox IntS_Num as a controlsource something like "=.......".
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  3. #3
    melhado
    Guest

    Re: Automatic incrementors, part 2 (Access 2K SR-1)

    Mark,

    "intS_Num" is a bound field in the table, not calculated. It holds the value that is later concatenated for display purposes at this stage, and subsequently becomes the new unit ID.

    Any other reason I could be getting that -- or is there a way around it?

    Thanks

    'dave

  4. #4
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Automatic incrementors, part 2 (Access 2K SR-1)

    The only other situation I could think of would be if the underlying recordset wasn't updatable.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  5. #5
    melhado
    Guest

    Re: Automatic incrementors, part 2 (Access 2K SR-1)

    <P ID="edit" class=small>Edited by melhado on 24-Aug-01 11:25.</P>It's a subform, and the underlying recordset is the table -- same table in the DMax code, the field in that line of code is the field that the text box is bound to.

    <font color=blue>Your mention of not updatable lead me to thinking that I may have corruption somewhere -- turns out the text box control apparently was corrupted, removing it and replacing it made it work.</font color=blue>

    Thanks for the direction.

    'dave

  6. #6
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Automatic incrementors, part 2 (Access 2K SR-1)

    >>Your mention of not updatable lead me to thinking that I may have corruption somewhere -- turns out the text box control apparently was corrupted, removing it and replacing it made it work.<<

    That's strange, but these things do happen. Often the only way to cure database problems is to create a new blank database and import all the objects from the bad database.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  7. #7
    melhado
    Guest

    Re: Automatic incrementors, part 2 (Access 2K SR-1)

    I was dreading that, but this seemed to be with the control, and your words, for some reason, lead me to try it -- am so glad I did <img src=/S/exclamation.gif border=0 alt=exclamation width=15 height=15>

    'dave

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •