Asked by:
Upgrade from Access 2000 - Office Automation question

Question
-
Hi all,
I wrote an Access 2000 application for my wife's medical laboratory 10+ years ago which still works fine.
However, H/W and OS issues required upgrade to later Access - I chose 2013 after reviewing professional forum comments.
The system converted very well with some minor issues all resolved.
The one remaining issue concerns Office Automation loading and populating / replacing pre-set fields with patient data prior to printing the report.
The following lines of code have not changed from the original and yet when I run them, they go to the 'On Error' routine.
-----------------------------------------------------------------------------------------
On Error GoTo mroMgmtSwitch_WordCall_Err
Do While Not snpReplaceCodes.EOF
'-- Get the actual value to replace with, then use the
' Word replace.
varReplaceWith = Eval(snpReplaceCodes!twcFormField)
varReplaceWith = IIf(IsNull(varReplaceWith), " ", CStr(varReplaceWith))With docWord.Content.Find
.Execute FindText:=snpReplaceCodes!twcReplace, _
ReplaceWith:=varReplaceWith, Format:=True, _
Replace:=wdReplaceOne
End With
snpReplaceCodes.MoveNext
Loop------------------------------------------------------------------------------
Can anyone please suggest what I can do?
We 70 year old has beens can't keep up with progress and need the assistance of more creative minds.
Thank you in anticipation.
Tuesday, October 18, 2016 5:28 AM
All replies
-
Hi FreoDocker,
Can you tell me what error it displayed?
I can see that you are trying find and replace with in loop till end of the file.
on which line you got an error?
if you can able to provide some more information regarding this code then it would be better to understand the code.
I am not able to understand why you are using word.
what's your desire output?
Regards
Deepak
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.Tuesday, October 18, 2016 7:16 AM -
Hi Deepak,
I believe I used word because of an example provide in Access 97 Power Programming.
Your question is excellent and has led me to change the approach - it will work very well using Access tables, forms and reports.
So thank you so much.
Kind regards,
FreoDocker
Thursday, October 20, 2016 9:05 AM -
Hi FreoDocker,
Below is an simple code for Find and Replace in file.
Option Compare Database Option Explicit Sub ReplaceStringInFile() Dim sBuf As String Dim sTemp As String Dim iFileNum As Integer Dim sFileName As String ' Edit as needed sFileName = "C:\Users\v-padee\Desktop\dem1.txt" iFileNum = FreeFile Open sFileName For Input As iFileNum Do Until EOF(iFileNum) Line Input #iFileNum, sBuf sTemp = sTemp & sBuf & vbCrLf Loop Close iFileNum sTemp = Replace(sTemp, "THIS", "THAT") iFileNum = FreeFile Open sFileName For Output As iFileNum Print #iFileNum, sTemp Close iFileNum End Sub
also I want to recommend you to check that did you update the library reference when you upgrade the Office to 2013 version?
if not then check it.
Go to VBE.
Click on "Tools" -> "References"
in the above mentioned code you are using MS Word.
so you need to Reference MS Word Library that support MS Office 2013 Version.
Let me know your issue solved or not.
Regards
Deepak
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.Friday, October 21, 2016 2:49 AM