UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Using Instr To Get Different Parts Of Long Text, Access 2010    
 
   
stevew295
post Nov 12 2019, 04:02 PM
Post#1



Posts: 79
Joined: 3-May 10



Access 2010, but also using/tested with 2016. Using bookmarks to insert text into a Word document. (Government Form, so have to follow the Form's setup) memo/long text field, so could have up to 8000+ characters.
First area on the Word doc(government form) allows up to approx 3600 characters. So, first part of the code inserts that first 3600 characters, or all of it if less than 3600 characters.

If (Len(Forms!MainForm!subform.Form!Description) > 3600) Then
Dim StrDesc1 As String
StrDesc1 = Left(Forms!MainForm!subform.Form!Description, InStr(3600, Forms!MainForm!subform.Form!Description, " "))

objWordDoc.bookmarks("Description1").Select
.selection.Text = StrDesc1 & "..." 'add 3 periods to make an ellipse.
Else
objWordDoc.bookmarks("Description").Select
.selection.Text = Forms!MainForm!subform.Form!Description
End If

The code above works, and fills in the first 3600 characters as intended.

Problem is the next part. "Description Continued 1" (on WordDoc/Government form): A little smaller area, so can only insert 2500 characters in this space.

what I want is: if > 3600 and < 6101 (3601+2500) then get all the text to the right of character 3600. BUT if the total text is > 6101, then insert characters between 3600 and 6101 here, and the remaining text in "Description Continued 2" which is also 2500 character max. So, possible total of 8600 characters. I don't even have a "guess code" for Description Continued 2 yet.

If (Len(Forms!MainForm!subform.Form!Description) > 3600) And (Len(Forms!MainForm!subform.Form!Description) < 6101) Then
MsgBox "yes it is >3600 & <6101"

Dim StrJobDesc2 As String
StrJobDesc2 = Right(Forms!MainForm!subform.Form!Description, InStr(3601, 1))

objWordDoc.bookmarks("DescriptionCont1").Select
.selection.Text = StrJobDesc2
End If

I'm temporarily using the msgbox for testing. MsgBox "yes it is >3600 & <6101 tells me that yes, it did evaluate the condition as true. (the test data was 3775 characters)
I then get error 462 The remote server machine does not exist or is unavailable. I'm not surprised it didn't work, and the error probly is because I'm doing it COMPLETELY wrong, but I have no idea on how to make it work.

Hopefully I made some sort of sense, thanks
Steve
This post has been edited by stevew295: Nov 12 2019, 04:03 PM
Go to the top of the page
 
theDBguy
post Nov 12 2019, 04:26 PM
Post#2


UA Moderator
Posts: 76,820
Joined: 19-June 07
From: SunnySandyEggo


Hi Steve. Not sure I follow, but the following will/should give you the first 3600 chars:

Left([LongText],3600)

The following should give you the next 2500 chars:

Mid([LongText],3601,2500)

But if it's possible, I would probably break down the input into separate textboxes with char limits, so you don't have to figure out where to cut each section and simply assign the appropriate control to the equivalent bookmark. For instance:

.selection.Text = Control1
.selection.Text = Control2
etc...

Hope that helps...
This post has been edited by theDBguy: Nov 13 2019, 12:10 PM
Reason for edit: Fixed typo...

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
stevew295
post Nov 12 2019, 04:54 PM
Post#3



Posts: 79
Joined: 3-May 10



Thanks theDBguy.

I will give Mid([LongText],2501,2500) a try, looks far easier than what I was trying to do.

as for your suggestion:

But if it's possible, I would probably break down the input into separate textboxes with char limits, so you don't have to figure out where to cut each section and simply assign the appropriate control to the equivalent bookmark. For instance:
.selection.Text = Control1
.selection.Text = Control2

Yes, that does sound much better, but not sure if users would agree to break up the input into 3 fields. But I will check with them.

Again, thanks.
Steve
Go to the top of the page
 
stevew295
post Nov 12 2019, 05:30 PM
Post#4



Posts: 79
Joined: 3-May 10



Just tested,

Left([LongText],3600)
The following should give you the next 2500 chars:
Mid([LongText],2501,2500)

does work just fine! Far better than what I was trying to do.

Thanks
Steve
This post has been edited by stevew295: Nov 12 2019, 05:30 PM
Go to the top of the page
 
theDBguy
post Nov 12 2019, 05:35 PM
Post#5


UA Moderator
Posts: 76,820
Joined: 19-June 07
From: SunnySandyEggo


Hi Steve. You're welcome. Since you're trying to fill out a government form, with character limits, your users should be okay (I say should) with also having character limits when filling out your form. Just my 2 cents... Good luck!

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
cheekybuddha
post Nov 13 2019, 07:55 AM
Post#6


UtterAccess Moderator
Posts: 11,870
Joined: 6-December 03
From: Telegraph Hill


>> Mid([LongText],2501,2500) <<

Shouldn't this be: Mid([LongText], 3601, 2500) ?

--------------------


Regards,

David Marten
Go to the top of the page
 
theDBguy
post Nov 13 2019, 12:10 PM
Post#7


UA Moderator
Posts: 76,820
Joined: 19-June 07
From: SunnySandyEggo


Oops, David, you're correct! Sorry for the typo...

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    7th December 2019 - 06:06 AM