Initiate a txt Search in Notepad via Access '00

G

Guest

I would like to be able to intiate a search in a Notepad document from a form
within my mdb. This form contains the control [IEXID] for which I would like
to search within Notepad. The Notepad doc will be open, but not active. The
mdb will be open and active.

The problem is I am simply not familiar enough with the commands and
utilities of VBA to write this code myself, though I'm guessing at some sort
of Shell method. Any help would be appreciated.

Thanks,

Corn
 
G

Guest

Doug,

Thanks for the quick reply.

Is there perhaps the possibility to save as rich text and open with Word?
Will this allow the search functionality? If so, please elaborate.

Corn
 
D

Douglas J. Steele

What exactly are you trying to do? If it's simply to find specific text in
the text file, you can open the file using VBA, store its content in a text
variable and use the InStr function to locate the text.

To open a file in VBA, you use the Open statement. To read it in line by
line, you can use the Line Input # statement, or you can use the Input
function to read the whole file.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Cornfused said:
Doug,

Thanks for the quick reply.

Is there perhaps the possibility to save as rich text and open with Word?
Will this allow the search functionality? If so, please elaborate.

Corn
 
G

Guest

Douglas J. Steele said:
What exactly are you trying to do? If it's simply to find specific text in
the text file, you can open the file using VBA, store its content in a text
variable and use the InStr function to locate the text.


Doug,

I'm checking adherence to schedules for 900+ reps in a call center. The way
this is done is a weekly audit of timesheets (viewable via IE) against one of
several txt reports (Notepad), with results recorded case by case into a mdb.

There is too much garbage in the txt report to import it into the db, at
least for my skill level (it is much akin to a Crystal report). So what I'd
like to do is to automate the manual lookup (currently "alt+tab, ctrl+F,
[IEXID], alt+tab"). Ideally, I would insert code into a specific control so
that "On Focus" runs the entire lookup for me.

Hope that makes sense.

Corn
 
D

Douglas J. Steele

Cornfused said:
Douglas J. Steele said:
What exactly are you trying to do? If it's simply to find specific text
in
the text file, you can open the file using VBA, store its content in a
text
variable and use the InStr function to locate the text.

I'm checking adherence to schedules for 900+ reps in a call center. The
way
this is done is a weekly audit of timesheets (viewable via IE) against one
of
several txt reports (Notepad), with results recorded case by case into a
mdb.

There is too much garbage in the txt report to import it into the db, at
least for my skill level (it is much akin to a Crystal report). So what
I'd
like to do is to automate the manual lookup (currently "alt+tab, ctrl+F,
[IEXID], alt+tab"). Ideally, I would insert code into a specific control
so
that "On Focus" runs the entire lookup for me.

Sorry, but that doesn't really tell me much. Are you simply trying to
determine whther the rep's name appears in the file (perhaps with some
specific text before or after it)? If so, then you should be able to use the
VBA approach I mentioned.

Perhaps if you posted some representative lines from the text file and
illustrate for what you're searching.
 
G

Guest

Sorry, but that doesn't really tell me much. Are you simply trying to
determine whther the rep's name appears in the file (perhaps with some
specific text before or after it)? If so, then you should be able to use the
VBA approach I mentioned.
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Yes, I would like Access to perform a find function in Notepad. The ID for
each record is displayed in an form, and I would like Access to take that ID
and locate it within the report. Once located, the audit will take place by
manually comparing the report to information displayed in a third window, IE.
In essence, what I'm trying to do is elimenate manual activity in one of the
three windows. It seems logical that Notepad, since it is only for
reference, would be most easily automated to display the record that is
currently displayed within the Access form.

Below is your requested sample: (6910 would be the text to find in this case)

6910 "Name of Individual" Date: 04/05/05

-----Scheduled----- ------Actual------- Scheduled Actual
Variance
From To Dur. From To Dur. Activity Activity
Description
----- ----- ----- ----- ----- ----- --------------------
-------------------- ---------------------------------------------------------
--:-- --:-- --:-- 12:30 12:31 00:01 Unstaff
Unscheduled event
12:30 13:30 01:00 --:-- --:-- --:-- Open Time

--:-- --:-- --:-- 12:31 13:31 01:00 Logon
Unscheduled event
13:30 14:00 00:30 --:-- --:-- --:-- Pre-Sched follow ups
 
D

Douglas J. Steele

Cornfused said:
Yes, I would like Access to perform a find function in Notepad. The ID for
each record is displayed in an form, and I would like Access to take that
ID
and locate it within the report. Once located, the audit will take place
by
manually comparing the report to information displayed in a third window,
IE.
In essence, what I'm trying to do is elimenate manual activity in one of
the
three windows. It seems logical that Notepad, since it is only for
reference, would be most easily automated to display the record that is
currently displayed within the Access form.

Below is your requested sample: (6910 would be the text to find in this
case)

6910 "Name of Individual" Date: 04/05/05

-----Scheduled----- ------Actual------- Scheduled Actual
Variance
From To Dur. From To Dur. Activity Activity
Description
----- ----- ----- ----- ----- ----- --------------------
-------------------- ---------------------------------------------------------
--:-- --:-- --:-- 12:30 12:31 00:01 Unstaff
Unscheduled event
12:30 13:30 01:00 --:-- --:-- --:-- Open Time

--:-- --:-- --:-- 12:31 13:31 01:00 Logon
Unscheduled event
13:30 14:00 00:30 --:-- --:-- --:-- Pre-Sched follow ups

As I've already suggested, you can use the VBA approach and read everything
into a text variable.

Once it's in the text variable, you can find the occurrence of 6910, and
find the first occurrence of Pre-Sched follow ups after that. Once you know
that, you can create a substring of the text and display it in a field in
your form, something like the following untested air-code:

Dim intFile As Integer
Dim lngFileSize As Long
Dim lngStart As Long
Dim lngStop As Long
Dim strAllText As String
Dim strFile As String
Dim strSpecific As String
Dim strToFind As String

' Set the person to find.
' Note that I'm putting a space after the value to minimize
' false finds. If you know there will be a space in front, use
' it as well, so that you'll only find what was between the spaces.
strToFind = "6910 "

' Make sure strFile actually exists
If Len(Dir$(strFile)) > 0 Then

' Determine how big the file is
lngFileSize = FileLen(strFile)

' Determine the next available FreeFile tag
' and open the file
intFile = FreeFile
Open strFile For Binary As intFile

' Initialize the variable to be big enough to contain the file,
' then read the entire file into the variable
strAllText = Space(lngFileSize)
Get #intFile, , strAllText
Close intFreeFile

' At this point, strAllText contains the entire content of the file
lngStart = InStr(strAllText, strToFind)
If lngStart > 0 Then
' Person was found at the position indicated by lngStart
lngStop = InStr(lngStart + 1, strAllText, "Pre-Sched follow ups",
1)
If lngStop > 0 then
' End phrase found starting at the position indicated by lngStop.
' Let's put everything in between into strSpecific.
' Note that you need to add 20 to lngStop since that's how much text
' is in the string for which we were searching
strSpecific = Mid$(strAllText, lngStart, (lngStop + 20) -
lngStart + 1))
Else
' End phrase not found: don't know what you want to do...
strSpecific = strToFind & " found, but end phrase wasn't"
Else
Else
' Person was not found in the text
strSpecific = strToFind & " was not found."
End If
End If

' Put either the found text, or the message into the form's field
Me.txtOutput = strSpecific

HTH.
 
G

Guest

Doug,

I guess I was explaning something more than what I wanted, but I've figured
out a solution in the interim. This is just a basic look-up function:

Private Sub NextRecord_Click()
On Error GoTo Err_NextRecord_Click

'Takes user to next record
DoCmd.GoToRecord , , acNext

'Setfocus on desired ID
IEXID.SetFocus

'Copy to buffer
RunCommand acCmdCopy

AppActivate "Notepad", True

SendKeys "%EG", True

SendKeys "1", True

SendKeys "{Enter}", True

SendKeys "{Esc}", True

SendKeys "%EF", True

SendKeys "^V", True

SendKeys "{Enter}", True

SendKeys "{Esc}", True

SendKeys "{pgdn}", True

AppActivate "Nonexempt Employee Time - Microsoft Internet Explorer"

Exit_NextRecord_Click:
Exit Sub

Err_NextRecord_Click:
MsgBox Err.Description
Resume Exit_NextRecord_Click

End Sub


This does what I need for now.

Thanks for your help.
 
D

Douglas J. Steele

I'd recommend very strongly against that approach, I'm afraid.

Using SendKeys can be very tempermental. If anyone does something to change
focus from Notepad (clicking on some other window while the code is supposed
to be working), you'll get totally unknown results.

However, if you're satisfied with it, good for you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top