Go Back   Access World Forums > Microsoft Access Discussion > Forms

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 08-24-2018, 02:41 AM   #1
MushroomKing
Newly Registered User
 
MushroomKing's Avatar
 
Join Date: Jun 2018
Location: The Netherlands
Posts: 88
Thanks: 55
Thanked 1 Time in 1 Post
MushroomKing is on a distinguished road
SendKeys from form and loop trough records

Hello dear people of Access world!

I have a question concerning passing data from a form with Sendkeys and looping until the last record.

- So i have a table with measurements and weights.
- I have a form based on this table with all the records.
- Access will open a program that we use and pass data with SendKeys
(for now i use notepad to see what happens fysically)

It has to take the first record and pass it through, then the procedure needs to loop until the last record and the code ends with a MsgBox or something like that.

What the best approach for looping through these records?
Thanks in advance guys!

Code:
Private Sub Command0_Click()

MsgBox "Please don't use the keyboard or mouse during the process. Thanks!"

AppActivate "notepad"

'first start ======================
SendKeys "{7}"
SendKeys "{ENTER}"
SendKeys "{ENTER}"
SendKeys Me.length
SendKeys "{ENTER}"
SendKeys Me.width
SendKeys "{ENTER}"
SendKeys Me.height
SendKeys "{ENTER}"
SendKeys Me.nw
SendKeys "{ENTER}"
SendKeys Me.bw
SendKeys "{ENTER}"
SendKeys "{ENTER}"
SendKeys "{F12}"
SendKeys "{7}"
SendKeys "{ENTER}"
SendKeys "{ENTER}"
SendKeys "{ENTER}"
'first end ======================

End Sub

MushroomKing is offline   Reply With Quote
Old 08-24-2018, 02:58 AM   #2
Minty
AWF VIP
 
Minty's Avatar
 
Join Date: Jul 2013
Location: UK - Wiltshire
Posts: 6,435
Thanks: 165
Thanked 1,738 Times in 1,707 Posts
Minty is a jewel in the rough Minty is a jewel in the rough Minty is a jewel in the rough
Re: SendKeys from form and loop trough records

Send keys will be about as reliable as a chocolate teapot I'm afraid.
Anything that might try and grab windows attention (an virus alert, IM alert, skype call notification etc. etc.) will intercept and then even worse interpret your keystrokes.

You will really need an API .
__________________
If we have helped please add to our reputation - click the scales symbol on the left, tick 'I approve' and leave a comment.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Minty is offline   Reply With Quote
The Following User Says Thank You to Minty For This Useful Post:
MushroomKing (08-24-2018)
Old 08-24-2018, 03:15 AM   #3
isladogs
High Noon Moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 10,999
Thanks: 114
Thanked 3,011 Times in 2,738 Posts
isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold
Re: SendKeys from form and loop trough records

Agree with Minty - don't use SendKeys. Slow & utterly unreliable

Here is a simple approach which will create a new text file & populate it or append text to an existing text file

Place this code in a standard module

Code:
Option Compare Database
Option Explicit

Const ForReading = 1, ForWriting = 2, ForAppending = 8

Dim objFso As Object
Dim logStream As Object
Dim fs As Object

'######################################
'#  Use this to create and append a text file with log entries
'#
'#  Parameters
'#      strLogEntry text to write eg "Hello world!"
'#  Usage
'#      LogEntry " Hello World!"
'#
'#  This will create or add to a file with: Hello World!
'#
'######################################
Sub LogEntry(strLogEntry As String)
  
    AddTextToFile "Full path to text file", strLogEntry
   'e.g. AddTextToFile "c:\TestFiles\Text.txt", strLogEntry
    'Debug.Print strLogEntry
End Sub

Sub AddTextToFile(strLogFile As String, strLogEntry As String)

'Identical to WriteToFile but without the date/time
    On Error Resume Next
    
    Set objFso = CreateObject("Scripting.FileSystemObject")
    Set logStream = objFso.OpenTextFile(strLogFile, ForAppending, True) 'Open log file
    
    logStream.writeline strLogEntry
    
    logStream.Close
End Sub
Example usage:
AddTextToFile CurrentProject.Path & "\test.txt", "Hello World"

You can also enter the path in LogEntry and save repeated typing
LogEntry "Goodbye"

Each entry will be added to a new line



If you wish, the current time can be added to each new line
Attached Images
File Type: png Capture.PNG (3.2 KB, 137 views)

__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Colin (Mendip Data Systems)
Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


"As we know, there are known knowns; there are things we know we know. We also know there are known unknowns; that is to say we know there are some things we do not know. But there are also unknown unknowns the ones we don't know we don't know. It is the latter category that tend to be the difficult ones" Donald Rumsfeld
isladogs is offline   Reply With Quote
The Following User Says Thank You to isladogs For This Useful Post:
MushroomKing (08-24-2018)
Old 08-24-2018, 03:38 AM   #4
MushroomKing
Newly Registered User
 
MushroomKing's Avatar
 
Join Date: Jun 2018
Location: The Netherlands
Posts: 88
Thanks: 55
Thanked 1 Time in 1 Post
MushroomKing is on a distinguished road
Re: SendKeys from form and loop trough records

Thanks guys.

But im afraid my hands are bound. I cannot create text files or save them to any location on this network. I only have a warehouse interface and an "approved Access application in my case".

I would just like to try this first.
So how can i move from the first record on my form to the last?

Cheers
MushroomKing is offline   Reply With Quote
Old 08-24-2018, 03:47 AM   #5
isladogs
High Noon Moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 10,999
Thanks: 114
Thanked 3,011 Times in 2,738 Posts
isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold
Re: SendKeys from form and loop trough records

Sorry - I thought you wanted to create a text file!!!

As for your question, I've no idea - I NEVER use SendKeys
__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Colin (Mendip Data Systems)
Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


"As we know, there are known knowns; there are things we know we know. We also know there are known unknowns; that is to say we know there are some things we do not know. But there are also unknown unknowns the ones we don't know we don't know. It is the latter category that tend to be the difficult ones" Donald Rumsfeld
isladogs is offline   Reply With Quote
The Following User Says Thank You to isladogs For This Useful Post:
MushroomKing (08-24-2018)
Old 08-24-2018, 03:51 AM   #6
MushroomKing
Newly Registered User
 
MushroomKing's Avatar
 
Join Date: Jun 2018
Location: The Netherlands
Posts: 88
Thanks: 55
Thanked 1 Time in 1 Post
MushroomKing is on a distinguished road
Re: SendKeys from form and loop trough records

Alright.

Well i use a text file on my own (development) laptop right now.
Just to see if the strokes work at all.

Seems to be fine.

I just need to loop through all the records on the form.
MushroomKing is offline   Reply With Quote
Old 08-24-2018, 04:28 AM   #7
JHB
Have been here a while
 
Join Date: Jun 2012
Location: In the south of Denmark (Jutland), near the German border.
Posts: 7,720
Thanks: 3
Thanked 2,082 Times in 2,037 Posts
JHB has a spectacular aura about JHB has a spectacular aura about
Re: SendKeys from form and loop trough records

Do you need to loop, else you can use <Ctrl> + <End>.

__________________
If the above post has helped you, why not take the time to say thank you, by pressing the "Thumbs up."
JHB is offline   Reply With Quote
The Following User Says Thank You to JHB For This Useful Post:
MushroomKing (08-24-2018)
Old 08-24-2018, 04:35 AM   #8
Gasman
Enthusiastic Amateur
 
Gasman's Avatar
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 4,363
Thanks: 434
Thanked 801 Times in 776 Posts
Gasman is a jewel in the rough Gasman is a jewel in the rough Gasman is a jewel in the rough
Re: SendKeys from form and loop trough records

Something along these lines then perhaps?

The debug line is where you put your code

Code:
Private Sub Command16_Click()
Me.Recordset.MoveFirst
Do Until Me.Recordset.EOF
    With Me.Recordset
        Debug.Print Me.ID
        .MoveNext
    End With
Loop
End Sub
HTH
__________________
Access novice. Sometimes trying to give something back.
Access 2007

Please, please use code tag # when posting code snippets

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Gasman is offline   Reply With Quote
The Following User Says Thank You to Gasman For This Useful Post:
MushroomKing (08-24-2018)
Old 08-24-2018, 05:15 AM   #9
MushroomKing
Newly Registered User
 
MushroomKing's Avatar
 
Join Date: Jun 2018
Location: The Netherlands
Posts: 88
Thanks: 55
Thanked 1 Time in 1 Post
MushroomKing is on a distinguished road
Re: SendKeys from form and loop trough records

Thanks Gasman!!!!!!

Yes, thats what i was looking for.

Only ONE more thing if you dont mind

The first record has a different procedure. And so does the last.
I would like to do something at the first record and then start the loop for the others. Also i want to stop at the second last record.
Because the last record has a different procedure.

I cant find anything on Movenext and second last on Google or the forum.
MushroomKing is offline   Reply With Quote
Old 08-24-2018, 05:27 AM   #10
Minty
AWF VIP
 
Minty's Avatar
 
Join Date: Jul 2013
Location: UK - Wiltshire
Posts: 6,435
Thanks: 165
Thanked 1,738 Times in 1,707 Posts
Minty is a jewel in the rough Minty is a jewel in the rough Minty is a jewel in the rough
Re: SendKeys from form and loop trough records

Movefirst positions you on first record. By definition movenext is therefore the "Second" record.

Movelast by definition gets you to one record after the second to last record...

All of this assumes you have 3 or more records in your recordset.
You can store the ID's if these records and check for them in your loop process.
__________________
If we have helped please add to our reputation - click the scales symbol on the left, tick 'I approve' and leave a comment.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Minty is offline   Reply With Quote
The Following User Says Thank You to Minty For This Useful Post:
MushroomKing (08-24-2018)
Old 08-24-2018, 06:57 AM   #11
MushroomKing
Newly Registered User
 
MushroomKing's Avatar
 
Join Date: Jun 2018
Location: The Netherlands
Posts: 88
Thanks: 55
Thanked 1 Time in 1 Post
MushroomKing is on a distinguished road
Re: SendKeys from form and loop trough records

Thanks minty

Ill try fix that and will come back to it.
I have a strange problem going on aside right now.

Im testing it.
It all seems to work fine.
Just when a value on the form for example is 0,99
It outputs it to notepad as 99

In my query there is 0,99
On my form its 0,99
But on output of the field (SendKeys Me.width) its 99

I tried formatting the query and the form, checked the tables...but to no avail
MushroomKing is offline   Reply With Quote
Old 08-24-2018, 06:09 PM   #12
JHB
Have been here a while
 
Join Date: Jun 2012
Location: In the south of Denmark (Jutland), near the German border.
Posts: 7,720
Thanks: 3
Thanked 2,082 Times in 2,037 Posts
JHB has a spectacular aura about JHB has a spectacular aura about
Re: SendKeys from form and loop trough records

Try by converting it to text using the CStr function.
__________________
If the above post has helped you, why not take the time to say thank you, by pressing the "Thumbs up."
JHB is offline   Reply With Quote
Old 08-26-2018, 11:23 PM   #13
MushroomKing
Newly Registered User
 
MushroomKing's Avatar
 
Join Date: Jun 2018
Location: The Netherlands
Posts: 88
Thanks: 55
Thanked 1 Time in 1 Post
MushroomKing is on a distinguished road
Re: SendKeys from form and loop trough records

Thanks JHB! Sounds like a good solution



Dim LValue As String
LValue = CStr(8)


So how would i go about this?

LVALUE = SendKeys Me!width


Like that?
MushroomKing is offline   Reply With Quote
Old 08-27-2018, 12:11 AM   #14
JHB
Have been here a while
 
Join Date: Jun 2012
Location: In the south of Denmark (Jutland), near the German border.
Posts: 7,720
Thanks: 3
Thanked 2,082 Times in 2,037 Posts
JHB has a spectacular aura about JHB has a spectacular aura about
Re: SendKeys from form and loop trough records

Like the below:
Code:
LVALUE = SendKeys CStr(Me!Width)
__________________
If the above post has helped you, why not take the time to say thank you, by pressing the "Thumbs up."
JHB is offline   Reply With Quote
Old 08-27-2018, 01:03 AM   #15
MushroomKing
Newly Registered User
 
MushroomKing's Avatar
 
Join Date: Jun 2018
Location: The Netherlands
Posts: 88
Thanks: 55
Thanked 1 Time in 1 Post
MushroomKing is on a distinguished road
Re: SendKeys from form and loop trough records

Thanks for that swift reply!

Code:
LVALUE = SendKeys CStr(Me!Width)

Expected end of statement...





Code:
LValue = CStr(Me!width)
Like this is ok ofcourse. But i need to send multiple keystrokes :S

MushroomKing is offline   Reply With Quote
Reply

Tags
form records , loop , records , sendkeys

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop through records in form speakers_86 General 1 12-19-2011 01:55 PM
loop trough records? js982 Modules & VBA 6 01-25-2009 01:17 AM
pass trough from form to report problem keydember Forms 4 09-08-2008 07:54 AM
[SOLVED] Can a memo field in different records be combined without SendKeys Mike375 General 22 01-05-2008 10:55 AM
Automated letters in WORD trough Form ?? Doppenberg Forms 1 09-07-2000 11:21 AM




All times are GMT -8. The time now is 11:52 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World