Link to home
Start Free TrialLog in
Avatar of slcscot
slcscot

asked on

Difficult Query Question

My table "Tbl_Check" has the following relevent fields:

CheckNum (primary key)
Comments (memo type field)

I use a form to update the table.  The form displays in one text box what's currently in the Comments field.  It has a second unbound textbox that allows new comments to be entered.

Upon clicking the update button, the new comments text box is captured into a string.

I use a DLookup function to pull the current comments from the table into a string.  I then concatenate the current comments with the new comments using the & operator into one supercomment string.

Here's my problem:
When I run my update query on my table to update the comments field with the new supercomment string (old and new comments together) If the total size of the new supercomment string is too large (say around 145ish characters) I get an error saying there's an invalid argument in my update query.

This process works FINE when the "old comments + new comments" length is not longer than around 145 characters.

I'm not sure how to get around this.  With all my debugging I can only determine that the update query does not like to use the SET operator with long variables.  I've tried using variants as well.

'Here's the part in the form where I display the data from the table into the form's text box:  (names are changed to make it easier to read)

Dim strComments As String
strComments = DLookup("Comments", "Tbl_Check", "[CheckNum] = '<numbergoeshere>'")
Forms!MyForm!CommentsTextBox = strComments

'When the edit button is clicked, i capture the second text box information, concatentate into a global form variable, and try to update the query with that variable, then update the form:

'Upon click event:

Public strAllComments As String  (NOTE: this string is global to the form, not declared under the button click event)
Dim strCurrentComments As String
Dim strNewComments As String
       
If (IsNull(Me.CommentsTextBox.Value)) Then
   strCurrentComments = ""
Else
   strCurrentComments = Me.CommentsTextBox.Value
End If
   
If (IsNull(Me.NewCommentsTextBox.Value)) Then
    strNewComments = ""
Else
    strNewComments = Me.NewCommentsTextBox.Value
End If


'CONCATENATION    
Me.strAllComments = strCurrentComments & " " & strNewComments
   
'RUN UPDATE QUERY - NOTE: CRASHES HERE WHEN strAllComments IS TOO LONG:
DoCmd.OpenQuery "Qry_Update_Comments"  

'Here's what my query looks like:
UPDATE Tbl_Check
SET Tbl_Check.Comments = [Forms]![MyForm].strAllComments
WHERE [Tbl_Check].[CheckNum]=[Forms]![MyForm]![<checknum variable here>];

'Now, this works most of the time. I've even tested the query itself by hardcoding the SET argument to be a really long long string.  No problems there.  When strAllComments is less than around 145 characters, the whole operation works wonderfully.  However, if the old comments are 140 characters, and I try to add more than 5 or so characters to the comments, strAllComments becomes too long.

Any insight into this?  I know a memo field can hold around 64000 chars, and a string either holds 32000 or 64000, either way, it should be plenty of room.  

Scot
ASKER CERTIFIED SOLUTION
Avatar of shanesuebsahakarn
shanesuebsahakarn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of slcscot
slcscot

ASKER

That worked wonderully!  Thank You