I am new to VB. In my VBA macro I am trying to access a data source(a text file) using the below code snippet.
Dim TESTING As String
..
..
TESTING = "M_1111" 'Accesing the value of M_1111 from data source
Selection.TypeText Text:=Chr(13)
Selection.TypeText Text:="TESTING"
Selection.TypeText Text:=Chr(13)
This works fine, if the value of M_1111 contains less number of characters. But if the value of M_1111 contains more number of characters, the value gets truncated upon accessing.
I don't know why this truncation is happening. Is there any maximum for the number of characters that can be accessed?
If so, the variable TESTING will always contain the text "M_1111" (it will not get a value from a data source). Also the value that is being typed is the text "TESTING", not the contents of your variable (to do that, remove the quotes).
When I run the code, I am able to get the value of M_1111 from the data source(which is a text file) . But the problem is that, if the value of M_1111 has more number of characters(more than around 200 characters), the value gets truncated.
there is nothing in the code you show that should truncate the value of .datafields(testing), try removing the first line as it may be causing an issue and you are not using it anyway
what is the size of the datafield testing?
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
What data type is it, and where does it come from?
I don't know anything about .DataFields, but I am guessing that it provides a link to a database. If so, and the field is a Memo data type, behaviour like this is not uncommon; The easy fix (the data is short enough) is to change the data type to a smaller text based data type (in Access 'Text', for others 'VarChar').
My data source is a simple text file of the following form:
M_1111,
"Visual Basic (VB) is a programming environment from Microsoft in which a programmer uses a graphical user interface to choose and modify preselected sections of code written in the BASIC programming language. Visual Basic is also widely used to write working programs. Microsoft says that there are at least 3 million developers using Visual Basic.",
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
as far as i can tell the length of the datasource.datafield has limitation
the alternative is to insert a merge field in the document, this will return the full length of the text
Last edited by westconn1; Feb 12th, 2008 at 06:39 AM.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
In the test code, I'm just printing the value of M_1111. So just using the merge field is an alternative.
But in the actual code(which I am yet to write), I need to get the value of merge field M_1111 (which has some separators) and split them and then print it at different places.