Hello all,
Could anybody give me the correct syntax for defining a loop using the
form's recordset for as long as it is not at the end of the table ?
example:
Do While not EOF ' this is the part I don't know
commands ....
.....
.....
Loop
Thanks ..... 10 2116
Ronny Sigo wrote: Hello all, Could anybody give me the correct syntax for defining a loop using the form's recordset for as long as it is not at the end of the table ?
example: Do While not EOF ' this is the part I don't know commands .... ..... ..... Loop
Thanks .....
Dim rst As Recordset
Set rst = Currentdb.Openr ecordset("MyTab le",dbopendynas et)
If rst.Recordcount > 0 then
rst.MoveFirst
Do while not rst.EOF
....process
rst.MoveNext
Loop
Endif
rst.close
set rst = Nothing
Hello Salad ...
Thanks for responding ...
I tried it as you suggested
Now I get the error message "Invalid argument" at the line where I put the
***********
tblFoutmeldinge n does exist ....
Here is the snippet ....
Dim rst As Recordset
Set rst = CurrentDb.Openr ecordset("tblFo utmeldingen", dbopendynaset)
***********
If rst.RecordCount > 0 Then
rst.MoveFirst
Do While Not rst.EOF
If [Karel] = True Then
sBody = sBody & "Apparaat: " & Trim([Apparaat]) & "
Beschrijving: " & Trim([Beschrijving]) & _
" Datum: " & [DatumMelding] & " Gebruiker: " &
Trim([Gebruiker]) & vbCrLf & _
Trim([Gebruiker]) & " probeerde dit te herstellen met
volgende handeling(en): " & Trim([OndernomenActie]) & vbCrLf & vbCrLf
[DatumMailKarel] = Date
End If
If [Ronny] = True Then
ronnylogic = True
End If
rst.MoveNext
Loop
End If
rst.Close
Set rst = Nothing
"Salad" <oi*@vinegar.co m> schreef in bericht
news:3F******** *******@vinegar .com...
Ronny Sigo wrote:
Hello all, Could anybody give me the correct syntax for defining a loop using the form's recordset for as long as it is not at the end of the table ?
example: Do While not EOF ' this is the part I don't know commands .... ..... ..... Loop
Thanks .....
Dim rst As Recordset Set rst = Currentdb.Openr ecordset("MyTab le",dbopendynas et) If rst.Recordcount > 0 then rst.MoveFirst Do while not rst.EOF ....process rst.MoveNext Loop Endif rst.close set rst = Nothing
You might be missing a reference to a DAO library. Go to Tools->References,
see if DAO is checked.
"Ronny Sigo" <ro********@sky net.be> wrote in message
news:3f******** **************@ feed0.news.be.e asynet.net... Hello Salad ... Thanks for responding ... I tried it as you suggested Now I get the error message "Invalid argument" at the line where I put the *********** tblFoutmeldinge n does exist .... Here is the snippet ....
Dim rst As Recordset Set rst = CurrentDb.Openr ecordset("tblFo utmeldingen", dbopendynaset) *********** If rst.RecordCount > 0 Then rst.MoveFirst Do While Not rst.EOF If [Karel] = True Then sBody = sBody & "Apparaat: " & Trim([Apparaat]) & " Beschrijving: " & Trim([Beschrijving]) & _ " Datum: " & [DatumMelding] & " Gebruiker: " & Trim([Gebruiker]) & vbCrLf & _ Trim([Gebruiker]) & " probeerde dit te herstellen met volgende handeling(en): " & Trim([OndernomenActie]) & vbCrLf & vbCrLf [DatumMailKarel] = Date End If If [Ronny] = True Then ronnylogic = True End If rst.MoveNext Loop End If rst.Close Set rst = Nothing
"Salad" <oi*@vinegar.co m> schreef in bericht news:3F******** *******@vinegar .com...
Ronny Sigo wrote:
Hello all, Could anybody give me the correct syntax for defining a loop using the form's recordset for as long as it is not at the end of the table ?
example: Do While not EOF ' this is the part I don't know commands .... ..... ..... Loop
Thanks .....
Dim rst As Recordset Set rst = Currentdb.Openr ecordset("MyTab le",dbopendynas et) If rst.Recordcount > 0 then rst.MoveFirst Do while not rst.EOF ....process rst.MoveNext Loop Endif rst.close set rst = Nothing
Ronny Sigo wrote: Hello Salad ... Thanks for responding ... I tried it as you suggested Now I get the error message "Invalid argument" at the line where I put the *********** tblFoutmeldinge n does exist .... Here is the snippet ....
Dim rst As Recordset Set rst = CurrentDb.Openr ecordset("tblFo utmeldingen", dbopendynaset) ***********
As Randy stated, you may be using ADO instead of DAO. You could set your
references or enter
Dim rst As DAO.Recordset
Otherwise the table name may be misspelled.
Hello all,
The DAO thing proved to be true, as you both said, and it also showed in the
help files. So I referenced it and now I don't get this error anymore. So
this is solved but .... now at the same line I get another errormssg saying
"Types don't match" (or something similar, 'cause the actual error message
is in Dutch) ....
Can you see why ? any help very much appreciated ....
Thanks,
Ronny
"Salad" <oi*@vinegar.co m> schreef in bericht
news:3F******** *******@vinegar .com... Ronny Sigo wrote:
Hello Salad ... Thanks for responding ... I tried it as you suggested Now I get the error message "Invalid argument" at the line where I put
the *********** tblFoutmeldinge n does exist .... Here is the snippet ....
Dim rst As Recordset Set rst = CurrentDb.Openr ecordset("tblFo utmeldingen", dbopendynaset) ***********
As Randy stated, you may be using ADO instead of DAO. You could set your references or enter Dim rst As DAO.Recordset
Otherwise the table name may be misspelled.
"Ronny Sigo" <ro********@sky net.be> wrote in message
news:3f******** **************@ feed0.news.be.e asynet.net... Hello all, The DAO thing proved to be true, as you both said, and it also showed in
the help files. So I referenced it and now I don't get this error anymore. So this is solved but .... now at the same line I get another errormssg
saying "Types don't match" (or something similar, 'cause the actual error message is in Dutch) ....
Can you see why ? any help very much appreciated .... Thanks, Ronny
Ronny
Your original question asks about a form's recordset which could be written
differently - e.g.
Private Sub cmdTest1_Click( )
On Error GoTo Err_Handler
With Me.RecordsetClo ne
If .RecordCount > 0 Then
.MoveFirst
While Not .EOF
Debug.Print Nz(.Fields(2), "")
.MoveNext
Wend
End If
End With
MsgBox "Done", vbInformation
Exit_Handler:
Exit Sub
Err_Handler:
MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler
End Sub
but a more generalised DAO loop might look more like this:
Private Sub cmdTest2_Click( )
On Error GoTo Err_Handler
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
strSQL = "SELECT tblCompanies.Co Name FROM tblCompanies " & _
"ORDER BY tblCompanies.Co Name"
Set dbs = CurrentDb
Set rst = dbs.OpenRecords et(strSQL)
While Not rst.EOF
Debug.Print Nz(rst!CoName, "")
rst.MoveNext
Wend
MsgBox "Done", vbInformation
Exit_Handler:
If Not rst Is Nothing Then
rst.Close
Set rst = Nothing
End If
If Not dbs Is Nothing Then
Set dbs = Nothing
End If
Exit Sub
Err_Handler:
Select Case Err.Number
'Handle specified errors here:
Case Else
MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler
End Select
End Sub
"Pink Panther" <Pi************ *@mail.com> wrote in message
news:ec******** *************** ***@posting.goo gle.com... Salad,
As a matter of interest why
If rst.Recordcount > 0 then rst.MoveFirst Do while not rst.EOF ....process rst.MoveNext Loop Endif
why not just
Do while not rst.EOF ....process rst.MoveNext Loop
?
Does the former avoid some kind of potential problem that I'm unaware of?
Regards,
Peter
Since the post started on the subject of a form's recordset, then it's
possible that the code contains
Set rst = Me.RecordsetClo ne
so that the recordset is based on the form's RecordsetClone. If this is the
case, then you may well not be at the beginning of a recordset - so in order
to loop through all the records you need to call MoveFirst. However, if the
form's underlying recordsource returns no records, or perhaps the user has
applied a filter to the form which returns no records, then this MoveFirst
will cause a 'no current record' runtime error. Therefore checking the
record count before calling MoveFirst both seem sensible steps.
If, however, the code contains
Set rst = dbs.OpenRecords et(strSQL)
There is no need to call MoveFirst and you can get straight on with While
Not rst.EOF or whatever.
HTH
Fletcher
Hello Arnold,
I used your "more generalised DAO loop", as you suggested. I get no error
messages anymore but ...
This thing serves to automatically generate an email message with the
contents of the tabls in it ...
By each rst.Move.Next, the sBody variable is updated with the old value +
the new one, finally forming the body of the emailmessage.
By using your loop, the email msg displays the correct number of lines
(according to the numer of records in the table - 9 at present (testing)).
The weird thing is that all 9 lines are displaying the values of the first
record, so I get 9 lines exactly the same ..... this beats me .....
Here is the code .... can you see why it does that ?
Private Sub btnStuurMails_C lick()
Forms!frmBekijk Foutmeldingen.R equery
Dim nLast As Long
Dim Email As String, Subject As String, sBody As String, attach As String
Dim cc As String, bcc As String
Subject = "Foutmelding(en )"
Email = "so*****@somepr ovider.be"
sBody = "Beste Karel," & vbCrLf & vbCrLf & _
"De volgende problemen werden mij gemeld. Weet jij hier een oplossing
voor?" & _
vbCrLf & "Met vriendelijke groeten," & vbCrLf & vbCrLf & _
"Steven Leman," & vbCrLf & _
"consulent ICT" & vbCrLf & vbCrLf
'DoCmd.GoToReco rd , , acFirst
tellerke = 0
Dim ronnylogic As Boolean
ronnylogic = False
' Here comes Fletcher's part ...
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
strSQL = "SELECT * FROM tblFoutmeldinge n"
Set dbs = CurrentDb
Set rst = dbs.OpenRecords et(strSQL)
Do While Not rst.EOF
If [Karel] = True Then
sBody = sBody & "Apparaat: " & Trim([Apparaat]) & "
Beschrijving: " & Trim([Beschrijving]) & _
" Datum: " & [DatumMelding] & " Gebruiker: " &
Trim([Gebruiker]) & vbCrLf & _
Trim([Gebruiker]) & " probeerde dit te herstellen met volgende
handeling(en): " & Trim([OndernomenActie]) & vbCrLf & vbCrLf
[DatumMailKarel] = Date
End If
If [Ronny] = True Then
ronnylogic = True
End If
rst.MoveNext
Loop
If Not rst Is Nothing Then
rst.Close
Set rst = Nothing
End If
If Not dbs Is Nothing Then
Set dbs = Nothing
End If
' Start Outlook.
' If it is already running, you'll use the same instance...
Dim olApp As Object
'Dim olApp As Outlook.Applica tion
Set olApp = CreateObject("O utlook.Applicat ion")
' Logon. Doesn't hurt if you are already running and logged on...
Dim olNs As Outlook.NameSpa ce
Set olNs = olApp.GetNamesp ace("MAPI")
olNs.Logon
'sFunctie = DLookup("[Functie]", "tblMwerker s", "[Volledigenaam] = '" &
sNaamschrijver & "'")
' Send a message to your new contact.
Dim olMail As Outlook.MailIte m
Set olMail = olApp.CreateIte m(olMailItem)
' Fill out & send message...
'olMail.To = olItem.Email1Ad dress
olMail.To = "so*****@somepr ovider.be"
olMail.Subject = "Foutmelding(en )"
olMail.body = sBody
olMail.Display
'olMail.Send
' Clean up...
Set olNs = Nothing
Set olMail = Nothing
Set olAppt = Nothing
Set olItem = Nothing
Set olApp = Nothing
End Sub
Salad,
As a matter of interest why If rst.Recordcount > 0 then rst.MoveFirst Do while not rst.EOF ....process rst.MoveNext Loop Endif
why not just
Do while not rst.EOF ....process rst.MoveNext Loop
?
Does the former avoid some kind of potential problem that I'm unaware of?
Regards,
Peter This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jeff_Relf |
last post by:
Hi Tom, You showed: <<
private const string PHONE_LIST =
"495.1000__424.1111___(206)564-5555_1.800.325.3333";
static void Main( string args ) {
foreach (string phoneNumber in Regex.Split (PHONE_LIST, "_+")) {
Console.WriteLine (phoneNumber); } }
Output:
495.1000
|
by: John Bailo |
last post by:
What is /automatic/ garbage collection, and how do I know that it is
really efficient?
If I use mono, I can look at the code.
But if I use Java and .NET -- I have no idea.
A brilliant programmer called Jeff Relf just discovered a more efficient
way of clearing memory -- does GC do this?
|
by: Carl Ribbegaardh |
last post by:
What other c++ constructs can I use instead of #define for executing a
couple of functions?
Example:
#define DO_STUFF doThis(); doThat();
I'd guess that I can either use a template function, an inlined function or
an inlined static method.
//1
|
by: jitendar.rawat |
last post by:
Hi,
I am trying to create a library and want its user to define a function
in their executable if that library is linked. some thing like, if some
uses my library and haven't defined a function like
void Initialize( long a, long b)
{
}
at link time I should get an error like "unresolved symbols"
I am able to get it done if I create a dummy fnction in header file of
|
by: Vinu |
last post by:
The following code doesn't prints anything why it is?
The code is correct. plz explain the logic
#include <stdio.h>
int arr = {10,20,30,40,50};
#define ARR_SIZE sizeof(arr)/sizeof(arr)
void main()
| |
by: Stuart Norris |
last post by:
Dear Readers,
I am attempting to define an array of IPAddress-es in C#.
I wish to have a array of address so I can try in order to connect to
them in a loop to handle unavailable hosts.
Todate since I do not know how to define an array of IPAddress-es. I
have been defining variable like:
|
by: David Isaac |
last post by:
I would like to be able to define a loop statement
(nevermind why) so that I can write something like
loop 10:
do_something
instead of
for i in range(10):
do_something
|
by: anjna22 |
last post by:
#define prvCheckDelayedTasks()
{
register tskTCB *pxTCB;
while((pxTCB = (tskTCB *)
listGET_OWNER_OF_HEAD_ENTRY(pxDelayedTaskList)) != NULL)
{
if(xTickCount < listGET_LIST_ITEM_VALUE( & (pxTCB-
}
}
|
by: anon.asdf |
last post by:
Hello!
In the following code-snippet, is it possible to initialize each
element of arr, with STRUCT_INIT?
struct mystruct {
int a;
char b;
};
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |