Jump to content

Getting information from notepad to Access Form.


Recommended Posts

I know I just made this post, but after searching the forums for the last few days I still can't seem to put my finger on a solution that works. Keep in mind I am very new to all of this. =(

CODE
; Get text from Notepad and Put it into Access or Notepad

;Create Variable

Dim $var1 = "No Text Grabbed"

Dim $grabPrimaryIndex, $grabSecondaryIndex, $grabDrawer, $grabFolderType, $grabDoctype

Dim $captureWin = "ImageRight Enterprise Scanner"

Dim $pasteWin = "Untitled - Notepad"

Dim $pasteAccess = "Microsoft Access - Acces_Project_Main : Database (Access 2000 file format)"

; Wait for page to appear

if WinWait($captureWin,"",5) Then

if WinActive($captureWin,"") = 0 then WinActivate($captureWin,"")

;Make sure the controls have all been updated... requires you to change the controls's focus

ControlFocus($captureWin,"","TEdit2")

Send ("{TAB}")

Sleep (500)

$grabPrimaryIndex = ControlGetText($captureWin,"","TEdit2")

$grabSecondaryIndex = ControlGetText($captureWin,"","TEdit1")

$grabDrawer = ControlCommand($captureWin,"","TComboBox3","GetCurrentSelection")

$grabFolderType = ControlCommand($captureWin,"","TComboBox2","GetCurrentSelection")

$grabDoctype = ControlCommand($captureWin,"","TComboBox1","GetCurrentSelection")

;Open Notepad.exe

if WinWait($pasteWin,"",1) = 0 Then run ("notepad.exe")

;Wait for Notepad to open

WinWait ($pasteWin, "")

if WinActive($pasteWin,"") = 0 then WinActivate($pasteWin,"")

if ControlCommand($captureWin,"","TButton3","IsEnabled") Then

$var1 = "Primary Index: " & @TAB & $grabPrimaryIndex & @CRLF

$var1 = $var1 & "Secondary Index: " & @TAB & $grabSecondaryIndex & @CRLF

$var1 = $var1 & "Drawer: " & @TAB & $grabDrawer & @CRLF

$var1 = $var1 & "Folder Type: " & @TAB & $grabFolderType & @CRLF

$var1 = $var1 & "Doc Type: " & @TAB & $grabDoctype & @CRLF

Else

$var1 = "BAD DATA!"

EndIf

ControlSetText ($pasteWin,"","Edit1",$var1)

;Paste info from notepad, into Access Database

WinWait ($pasteAccess, "ImageRight_1")

if WinActive($pasteAccess,"ImageRight_1") = 0 Then WinActivate($pasteAccess,"ImageRight_1")

if ControlGetText($pasteWin,"","Edit1","IsEnabled") Then

$var1 = ClipPut($grabPrimaryIndex)

Send ("{TAB}")

$var1 = ClipPut($grabSecondaryIndex)

Send ("{TAB}")

$var1 = ClipPut($grabDrawer)

Send ("{TAB}")

$var1 = ClipPut($grabFolderType)

Send ("{TAB}")

$var1 = ClipPut($grabDoctype)

ControlSetText($pasteAccess,"ImageRight_1",,$var1)

Endif

;Only enable in final production, clicks the scan button if possible.

if ControlCommand($captureWin,"","TButton3","IsEnabled") Then ControlClick ($captureWin,"","TButton3")

EndIf

The area in bold is what I have so far for getting the information from notepad, to the Access form. I know something is wrong with my if, then statements, but what I'm really missing is the right function / method for getting that data where it needs to go.

I was hoping that since I assigned the information I wanted to their respective variables, I would be able to just call those variables again with the same information, but I'm not sure this is the case.

I looked into ADODB.connection as someone recommended, but either because of my inexperience or perspective, I couldn't seem to make enough sense out of it to make any use of it.

Someone please help me! =(

Link to comment
Share on other sites

Why did you start another topic? You should have just continued in the existing one:

http://www.autoitscript.com/forum/index.ph...c=95306&hl=

After bumping it a few more times I still didn't receive a reply, so I thought maybe a I should rework the post the be a bit more clear on what I was looking for, what I had in terms of code, what I was having trouble with specifically, and what I had tried as far as forum searches go.

Link to comment
Share on other sites

After bumping it a few more times I still didn't receive a reply, so I thought maybe a I should rework the post the be a bit more clear on what I was looking for, what I had in terms of code, what I was having trouble with specifically, and what I had tried as far as forum searches go.

Bump

Link to comment
Share on other sites

It is pretty hard to help you since we do not know if you are sending info into an Access form with one single field or several fields or an Access table or ....?

I'm just going to pick one - I'll assume that you need to send:

info

tab

info

tab

~~~~

You probably made a copy/paste error in this If line,

but you do not want/need that If line

(at least not coded like that):

if ControlGetText($pasteWin,"","Edit1","IsEnabled") Then

if ControlCommand($pasteWin,"","Edit1","IsEnabled") Then

$var1 = ClipPut($grabPrimaryIndex)

This line ^^^

...does not do what you think it does.

It puts the info stored in $grabPrimaryIndex into the Windows clipboard.

If the operation of putting that info into the clipboard is successful,

then $var1 is assigned the number 1.

If it fails - then $var1 is assigned the number 0.

When you get ready to send the info...

make sure that the window is active

then just do this.......

Send($grabPrimaryIndex)

Send("{TAB}")

...stay away from the windows clipboard for now

Save that as an improvement once you get it working.

Now back to this part of your code:

; Wait for page to appear

if WinWait($captureWin,"",5) Then

if WinActive($captureWin,"") = 0 then WinActivate($captureWin,"")

;Make sure the controls have all been updated... requires you to change the controls's focus

ControlFocus($captureWin,"","TEdit2")

I see no reason to have a timeout in your WinWait line. If the window does not appear within 5 seconds, your script will continue! Why would you want it to continue? [< Rhetorical] It will only fail.

The next line "says" if the window is not active, activate it.

If the window was inactuve for some reason, then activating it may take a millisecond or two - but your code attempts to set the focus of a control right away (perhaps before the window is active). AutoIt attempts to take care of this for you with some built in delays, but they might not always be long enough. It might be better to code that part like this:

; Wait for page to appear

WinWait($captureWin,"")

WinActivate($captureWin,"")

WinWaitActive($captureWin,"")

;Make sure the controls have all been updated...

;requires you to change the controls' focus

Do

Sleep(50)

Until ControlFocus($captureWin,"","TEdit2")

The code above it not that great because it might make your script halt/hang. For instance, if that control never comes into focus - then the script will just set there in that Do/Until loop until you manually kill it.

The goal here is to show you that you do not want your script to continue if that control has not done what you want it to do. Better code would be to pop up a MsgBox or some other warning that the script has hung up there - but to keep it simple - run your code as an AU3 text file (uncompiled) and use this OPT setting at the top of your script:

AutoItSetOption ("TrayIconDebug", 1) ;0-off

If the script appears to hang/stop, put your mouse over the AutoIt icon in the system tray until a ToolTip tells you what line the script is stuck on.

You have the basic layout correct:

Activate the first window

Get data

Activate the second window

Send data

Give it a try again.

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...