Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    KrisDdb is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    58

    Question Character limit for Unbound Textbox on Form

    I have a form with a couple of unbound text boxes and combo boxes. I can edit the text boxes and select different options in the combo boxes, and save with these updates in a table. For this I use an update query, that runs whenever I click on the save button on the form.
    The problem: when I try to put large amount of text (exceeding 255 characters) in one textbox, say ‘txtNote’ and save it, I get a “runtime error - 3271 : Invalid property value”.
    Points to note:
    · The field in the table (say ‘Note’) where it saves the txtNote entry is a ‘memo’ datatype. So that’s not the reason for the problem!
    · Our software application reflects the data from this table in its fields.


    · When I input the text in the software in the concerned field directly (even more than 255 chars can be typed in the software side) and then try to display it in the form, it does so in the txtNote! It doesn’t truncate the extra characters.
    So now the question is, how do I make the textbox on the form accept more characters than 255 and save it?? Let me know if I should provide more information.

    Thanks for your time and thoughts.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Why are your controls *not* bound?

  3. #3
    KrisDdb is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    58
    Thanks for your reply.

    As for your question, the field that i am dealing with here is a multi-user field. And i believe, if I use a bound control, it would keep the record locked until it is totally written. Whereas with the unbound control, it locks the record only at the moment of saving it. I wouldnt want to lose this functionality for my users.

    Not sure if this might help: I have tried using the bound controls too, to do the updates. In this case I noticed something that I haven't seen before! After I hit the 'save' button, I still get the "runtime error 3271". However, after I close the error window, I see that the data is saved back to the table, and it even reflects in the software application fields. Though this method is doing the updates, its pretty annoying if you have to see an error pop-up everytime you try to add a note longer than 255 chars, which is quite often in my case. I would be relieved if there were a way to bypass this error at least!!

    Any suggestions?

    Note: Pls correct me if I am wrong about my impression of bound/unbound controls.

  4. #4
    KrisDdb is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    58
    Is there atleast a way to trap the error? some kind of error handling so the users dont get to know about this?? Even that should suffice if it wont put any breaks in the execution!
    ()

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    How about a temporary table that is local to the PC and then an UPDATE or APPEND.

  6. #6
    KrisDdb is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    58

    Thumbs up Got the fix!!

    @ RuralGuy: I got the problem solved And I apologise for the late reply.

    Since the original code was working, I was trying to just set a trap for the error it was throwing up. Also it was a runtime error. So I could see that the text box was taking up the data.. only it couldnt pass it on to the table. Creating a temp table and update query seemed extra work. Also, I wanted to use as little code as possible. But it sure was an interesting thought.

    So this is what I did. I put the below line of code before the execution of the code for the textbox

    On Error Resume Next

    which trapped the error. That might not be the best way to do it, but it serves the purpose. I never had to use an error trap before, so I was breaking my head on it But with a little googling and 'forumming', I got the fix. Thanks for all your thoughts and time.

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You would be better to trap the error you want to ignore only. You are now basically ignoring *any* error then you get.

  8. #8
    KrisDdb is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    58

    Thumbs up

    hmm! I see what you mean. I did not realise for a second that I was just ignoring it and not actually trapping it. So I should rather be calling it 'error handling' instead of 'error trapping'
    But anyways, I could not find a way to trap it. And eventually I had to come up with this.

  9. #9
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    What is the code you have under your save button starting with Private Sub ... on thru End Sub. Copy and paste here so we can see it if you can. Using the Code Tags helps too (the # sign in advanced posting)

  10. #10
    KrisDdb is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    58
    This is the code:

    Code:
     
    Private Sub Command4_Click()
        
        Dim st As String
        st = "frmDetailed"
        
        
        Dim db As DAO.Database
        Set db = CurrentDb
        
        Dim qd As DAO.QueryDef
        Set qd = db.QueryDefs("updateQuery")
        
        qd.Parameters("note_key") = Me.Text14
        qd.Parameters("Staff") = Me.List16
        qd.Parameters("Topic") = Me.List18
           On Error Resume Next
        qd.Parameters("Note") = Me.Text12
     
        
        qd.Execute
        
        DoCmd.Close acForm, st
        
    End Sub
    When I click the save button, the update query runs using the parameters given and thus saves in the table behind. That is where I was facing the error when I was tryin to pass more than 255 chars through Text12. I would rather like to use an error trap that would trap only the error 3151 instead of using On Error Resume Next. But I couldnt come up with one.

  11. #11
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Try this code:
    Code:
    Private Sub Command4_Click()
       On Error GoTo ErrorHandler
       '-- I don't think you need the following 2 lines
       '   Dim db As DAO.Database
       '   Set db = CurrentDb
       Dim qd As DAO.QueryDef
       Set qd = CurrentDb.QueryDefs("updateQuery")
       qd.Parameters("note_key") = Me.Text14
       qd.Parameters("Staff") = Me.List16
       qd.Parameters("Topic") = Me.List18
       qd.Parameters("Note") = Me.Text12
       qd.Execute
    ExitLabel:
       On Error Resume Next
       Set qd = Nothing
       DoCmd.Close acForm, Me.Name, acSaveNo
    ErrorHandler:
       If Err.Number <> 3271 Then
          '-- Show all other errors
          MsgBox "Error No:    " & Err.Number & vbCr & _
                 "Description: " & Err.Description
       End If
       Resume ExitLabel
    End Sub

  12. #12
    KrisDdb is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    58
    Quote Originally Posted by RuralGuy View Post
    Try this code:
    Code:
    Private Sub Command4_Click()
    On Error GoTo ErrorHandler
    '-- I don't think you need the following 2 lines
    ' Dim db As DAO.Database
    ' Set db = CurrentDb
    Yep! I agree I do not need them. I put them in so that I dont have to repetitively type CurrentDb in the future, if need be
    And coming to the code, after I tried your code, I used to get the msg box with Error: 0 and Description: (nothin in here)
    I tweaked it a bit, and now it works like a charm. Would really appreciate it if you could let me know if there are still any discrepancies with it.
    Heres my code:
    Code:
        On Error GoTo ErrorHandler
        
        Dim qd As DAO.QueryDef
        Set qd = CurrentDb.QueryDefs("uqryNote")
        qd.Parameters("note_key") = Me.Text14
        qd.Parameters("Staff") = Me.List16
        qd.Parameters("Topic") = Me.List18
        qd.Parameters("Note") = Me.Text12
        qd.Execute
        
    ErrorHandler:
        If Err.Number = 3271 Then
        
            Resume ExitLabel
            
        Else
            
            MsgBox "Error No:     " & Err.Number & vbCr & _
                   "Description:  " & Err.Description
               
        End If
        
    ExitLabel:
        On Error Resume Next
        Set qd = Nothing
        DoCmd.Close acForm, Me.Name, acSaveNo
    This prevents from getting the error prompt everytime the error is 3271. Also, I believe this would throw up the prompt when I get a different error.

    Thankyou again for your valuable input.

  13. #13
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Your code always falls through the ErrorHandler and mine does not.

  14. #14
    KrisDdb is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    58

    Thumbs up This should be it!!?

    Hmm.. that makes sense. But I did not want the msgbox to pop up evn when there was no error. After considering your last input, I am using this:
    Code:
    On Error GoTo ErrorHandler
     
    Dim qd As DAO.QueryDef
    Set qd = CurrentDb.QueryDefs("uqryNote")
    qd.Parameters("note_key") = Me.Text14
    qd.Parameters("Staff") = Me.List16
    qd.Parameters("Topic") = Me.List18
    qd.Parameters("Note") = Me.Text12
    qd.Execute
    DoCmd.Close acForm, Me.Name
     
    Exit Sub
     
    ErrorHandler:
    If Err.Number = 3271 Then
     
    Resume ExitLabel
     
    Else
    MsgBox "Error No: " & Err.Number & vbCr & _
    "Description: " & Err.Description
     
    End If
    ExitLabel:
    On Error Resume Next
    Set qd = Nothing
    DoCmd.Close acForm, Me.Name
    I believe now it doesnt go to the error handler always. Opinions/suggestions?
    p.s: thanks to you, I have realised and learnt some simple but important things

  15. #15
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    The code I posted would not have poped up a MsgBox unless there was an error other than 3271.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Unbound textbox and report linked to vba
    By Shambler2 in forum Programming
    Replies: 7
    Last Post: 06-09-2011, 04:29 PM
  2. Display PASS or FAIL using Unbound textbox
    By Shambler2 in forum Reports
    Replies: 7
    Last Post: 06-02-2011, 11:19 AM
  3. Replies: 5
    Last Post: 05-18-2011, 11:02 AM
  4. Text Box control and character limit?
    By Bigdoggit in forum Forms
    Replies: 2
    Last Post: 03-29-2011, 10:05 AM
  5. Replies: 4
    Last Post: 10-07-2010, 09:42 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