Results 1 to 10 of 10
  1. #1
    easyrider is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Dec 2021
    Location
    Lancaster County, PA
    Posts
    44

    Error 3271 - Invalid Property Value using DAO.Database with over 255 characters

    Hello all. I have always used Parameterized QueryDef procedures to insert/update tables with a DAO.Database variable. Everything always worked just great.

    Until now.

    The above error occurs when a text field (memo/notes) contains more than 255 characters - regardless of the LongText type declaration in the table field as well as in the qdef parameter declaration. After some googling I've learned that DAO cannot handle fields that have more than 255 characters and if a "notes" field goes over this limit, it generates the error mentioned in the lead of this post. I've seen some suggestions to use ADO instead and have been comparing & contrasting the differences. Seems like DAO is great for local DB's while ADO is better for client-server applications.

    I plan on splitting the DB, in the near future, and putting the back end on the company's SharePoint site then giving users of different departments a front end for any functions that they will need: HR, IT, Management, etc.

    Here is a stripped down sample of my existing code:

    Private Sub AddUser_BTN_Click()
    Dim strSQL As String
    Dim db As DAO.Database
    Dim qdef As QueryDef

    strSQL = "PARAMETERS " _
    & "UserNameVAR TEXT(255), NotesVAR LONGTEXT; " _
    & "INSERT INTO User_T " _
    & "(UserName, Notes) " _
    & "VALUES " _
    & "(UserNameVAR, NotesVAR);"

    Set db = CurrentDb
    Set qdef = db.CreateQueryDef("", strSQL)

    qdef.Parameters("UserNameVAR") = Me.UserName
    qdef.Parameters("NotesVAR") = Me.Notes

    qdef.Execute dbFailOnError
    db.Close
    Set qdef = Nothing
    Set db = Nothing

    End Sub


    So, my questions are:

    1. Should I learn & use ADO instead of DAO?
    2. Given that ADO is geared more for client-server applications, would this be relevant in a split DB scenario?
    3. I've seen some suggestions to use a procedure w/ DAO.RecordSet instead - particularly with the 'notes" field in question.

    What do you guys think?

    Thanks,


    -Bill

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Hi Bill,
    Could you try to save the query as a saved append query without specifying the parameters but simply point to the two form controls? I've been using this method for quite a while with no issues.
    Code:
    Dim qdf as DAO.QueryDef
    Dim prm as Parameter
    
    Set qdf=CurrentDb.QueryDefs("qryYourAppendNotes")
    
    For each prm in qdf.parameters
         Prm.Value=Eval(prm.Name)
    Next prm
    
    ' now run the query
    qdf.Execute dbFailOnError
    
    Set qdf=Nothing
    Cheers,
    Last edited by Gicu; 03-04-2023 at 07:36 PM.
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    easyrider is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Dec 2021
    Location
    Lancaster County, PA
    Posts
    44
    interesting approach, Vlad. Let me work on it tomorrow after the race and I'll report back on my results. Thanks!

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Sure Bill, please note I typed it on my phone and I see some auto-correct errors, I'll try to fix it when I get home to my laptop later today.
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    easyrider is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Dec 2021
    Location
    Lancaster County, PA
    Posts
    44
    Been playing around with your code Vlad and still getting the 3271 error - but only if I exceed 255 characters in the notes field. On the attached DB, the edit user form has an "Update Notes" button and your code is assigned to it. You'll see that I've placed a couple MsgBox's in the code to indicate what the values are - for T/S purposes.

    The notes field has exactly 255 characters. If you open the Edit User form and add 1 more character to it, it throws the error.

    CodeTestingDB.zip

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Hi Bill,
    Sorry for the delay, I had a look at your sample and you are right, there is a limitation with the DAO parameters that limits them to 255 characters as shown in these links (you've probably already seen them ):
    https://stackoverflow.com/questions/...ing-dao-object
    https://stackoverflow.com/questions/...-and-ms-access

    Anyway, I have incorporated the Eval() function straight into the update query so we can now just call the CurrentDb.Execute method on it. And included few other alternatives just in case.
    https://www.devhut.net/ms-access-vba...-query-in-vba/
    Attached Files Attached Files
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  7. #7
    easyrider is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Dec 2021
    Location
    Lancaster County, PA
    Posts
    44
    Vlad,

    Yeah I saw those articles plus some others. Thanks for the Eval function and the alternatives - I need to look into that Eval function some more, especially since I seem to have advanced from "novice" to "advanced beginner." LOL

    I tested all four of them and they all work as expected. Do you think I need to be concerned with SQL Injection w/ any of those methods?

  8. #8
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Hi Bill, I am no security expert but I would say you shouldn't worry about SQL injection unless your front-end is exposed to the internet. In a regular network deployment of FE\BE all four methods should be safe.

    Cheers,

  9. #9
    easyrider is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Dec 2021
    Location
    Lancaster County, PA
    Posts
    44
    I ended up using the 3rd method in Vlad's submission- the DAO.Recordset. For anybody else that stumbles on this thread in the future, the code looks like this and solves the problem that I originally posted:

    Code:
    Dim rs As DAO.Recordset
       Set rs = CurrentDb.OpenRecordset("SELECT User_T.* FROM User_T WHERE User_ID = " & Me.User_ID, dbOpenDynaset)
            rs.Edit
            rs("Notes") = Me.Notes
            rs.Update
            rs.Close
       Set rs = Nothing
    Thanks, Vlad!

    In closing, I'll throw out a little bit of humor that I stumbled on while digging around for an answer - before coming here. It's not exactly relevant to the thread, but funny nonetheless:

    Click image for larger version. 

Name:	exploits_of_a_mom.png 
Views:	15 
Size:	31.2 KB 
ID:	49884

    link here

  10. #10
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Replies: 21
    Last Post: 07-26-2018, 11:50 AM
  2. Replies: 4
    Last Post: 02-17-2016, 01:53 PM
  3. .Bookmark property invalid
    By MatthewGrace in forum Programming
    Replies: 3
    Last Post: 11-25-2015, 05:21 PM
  4. Compile Error: Invalid user of property
    By jwill in forum Programming
    Replies: 16
    Last Post: 11-20-2012, 05:23 PM
  5. VBA Import Error on Invalid Characters
    By jhrBanker in forum Import/Export Data
    Replies: 2
    Last Post: 11-25-2009, 12:07 PM

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