Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Looping through Records question

 
   Database Forums (Home) -> Visual Basic -> DAO RSS
Next:  DAO mdb to SQL Server Express?  
Author Message
Kimberley

External


Since: Jan 24, 2007
Posts: 3



(Msg. 1) Posted: Wed Jan 24, 2007 9:04 am
Post subject: Looping through Records question
Archived from groups: microsoft>public>vb>database>dao (more info?)

Hi all,
I have a table in access (tbl_ReportList) that has four fields (ID,
Emailto, CC, and RptName). The email and CC fields both have e-mail
addresses in them and the RptName field is a list of reports in the
database. For now I only have three: Report1,Report2,Report3.
When I run the code below, the same report "Report1" keeps getting
sent. Can someone please tell me what I'm doing wrong in the loop. For
now, I only have three reports but by the end it will be about 150.
Thanks in advance for any help,

Private Sub Command0_Click()
Dim db As database
Dim rst As DAO.Recordset
Dim x As Integer
Dim Emailto As String
Dim CC As String
Dim RptName As String


Set db = CurrentDb()
Set rst = db.OpenRecordset("tbl_ReportList", dbOpenDynaset)


With rst
If Not (.EOF And .BOF) Then
rst.MoveFirst
Do Until rst.EOF
For x = 1 To 140
Emailto = DLookup("EmailtoName", "tbl_ReportList")
CC = DLookup("CCName", "tbl_ReportList")
RptName = DLookup("ReportName", "tbl_ReportList")


DoCmd.SendObject acReport, RptName, "SnapshotFormat(*.snp)", _
Emailto, CCto, "", "Attention Required Report", "", False,
""
rst.MoveNext
Next
Loop
End If
End With


rst.Close
Set rst = Nothing
Set db = Nothing


End Sub

 >> Stay informed about: Looping through Records question 
Back to top
Login to vote
Kimberley

External


Since: Jan 24, 2007
Posts: 3



(Msg. 2) Posted: Wed Jan 24, 2007 2:48 pm
Post subject: Re: Looping through Records question [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Thanks for your reply. In answer to your question, RptName cannot
contain a string.
It contains only one report name. Each row in the table has the
following:
ID ReportName EmailtoName CCName
1 Report1 mbrown DeleteThis @public.com jjohnson DeleteThis @public.com

What I want to do is send the Report1 to the EmailtoName and the
CCName listed in the same row. And then move on to the next one.
I followed your advice but I am still getting the same report (Report1)
over and over.

On Jan 24, 4:56 pm, "Douglas J. Steele"
wrote:
> Do you mean that RptName can contain a string like
> "Report1,Report2,Report3"? If so, you really should read up on database
> normalization: storing multiple values in a single field is a bad idea.
>
> If RptName is a single report name, then you need to take advantage of the
> fact that you've opened a recordset. Using DLookup is going to return the
> same value every time.
>
> The 3 lines
>
> Emailto = DLookup("EmailtoName", "tbl_ReportList")
> CC = DLookup("CCName", "tbl_ReportList")
> RptName = DLookup("ReportName", "tbl_ReportList")
>
> should be
>
> Emailto = rst!EmailtoName
> CC = rst!CCName
> RptName = rst!ReportName
>
> --
> Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
> (no private e-mails, please)
>
> "Kimberley" wrote in messagenews:1169658283.200316.142520@v45g2000cwv.googlegroups.com...
>
>
>
> > Hi all,
> > I have a table in access (tbl_ReportList) that has four fields (ID,
> > Emailto, CC, and RptName). The email and CC fields both have e-mail
> > addresses in them and the RptName field is a list of reports in the
> > database. For now I only have three: Report1,Report2,Report3.
> > When I run the code below, the same report "Report1" keeps getting
> > sent. Can someone please tell me what I'm doing wrong in the loop. For
> > now, I only have three reports but by the end it will be about 150.
> > Thanks in advance for any help,
>
> > Private Sub Command0_Click()
> > Dim db As database
> > Dim rst As DAO.Recordset
> > Dim x As Integer
> > Dim Emailto As String
> > Dim CC As String
> > Dim RptName As String
>
> > Set db = CurrentDb()
> > Set rst = db.OpenRecordset("tbl_ReportList", dbOpenDynaset)
>
> > With rst
> > If Not (.EOF And .BOF) Then
> > rst.MoveFirst
> > Do Until rst.EOF
> > For x = 1 To 140
> > Emailto = DLookup("EmailtoName", "tbl_ReportList")
> > CC = DLookup("CCName", "tbl_ReportList")
> > RptName = DLookup("ReportName", "tbl_ReportList")
>
> > DoCmd.SendObject acReport, RptName, "SnapshotFormat(*.snp)", _
> > Emailto, CCto, "", "Attention Required Report", "", False,
> > ""
> > rst.MoveNext
> > Next
> > Loop
> > End If
> > End With
>
> > rst.Close
> > Set rst = Nothing
> > Set db = Nothing
>
> > End Sub- Hide quoted text -- Show quoted text -

 >> Stay informed about: Looping through Records question 
Back to top
Login to vote
Kimberley

External


Since: Jan 24, 2007
Posts: 3



(Msg. 3) Posted: Wed Jan 24, 2007 3:14 pm
Post subject: Re: Looping through Records question [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

I also had a couple of things named incorrectly. But removing the
DLOOKUP and using recordset worked perfectly.

Thanks again for your help

On Jan 24, 5:48 pm, "Kimberley" wrote:
> Thanks for your reply. In answer to your question, RptName cannot
> contain a string.
> It contains only one report name. Each row in the table has the
> following:
> ID ReportName EmailtoName CCName
> 1 Report1 mbr....RemoveThis@public.com jjohn....RemoveThis@public.com
>
> What I want to do is send the Report1 to the EmailtoName and the
> CCName listed in the same row. And then move on to the next one.
> I followed your advice but I am still getting the same report (Report1)
> over and over.
>
> On Jan 24, 4:56 pm, "Douglas J. Steele"
>
>
>
> wrote:
> > Do you mean that RptName can contain a string like
> > "Report1,Report2,Report3"? If so, you really should read up on database
> > normalization: storing multiple values in a single field is a bad idea.
>
> > If RptName is a single report name, then you need to take advantage of the
> > fact that you've opened a recordset. Using DLookup is going to return the
> > same value every time.
>
> > The 3 lines
>
> > Emailto = DLookup("EmailtoName", "tbl_ReportList")
> > CC = DLookup("CCName", "tbl_ReportList")
> > RptName = DLookup("ReportName", "tbl_ReportList")
>
> > should be
>
> > Emailto = rst!EmailtoName
> > CC = rst!CCName
> > RptName = rst!ReportName
>
> > --
> > Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
> > (no private e-mails, please)
>
> > "Kimberley" wrote in messagenews:1169658283.200316.142520@v45g2000cwv.googlegroups.com...
>
> > > Hi all,
> > > I have a table in access (tbl_ReportList) that has four fields (ID,
> > > Emailto, CC, and RptName). The email and CC fields both have e-mail
> > > addresses in them and the RptName field is a list of reports in the
> > > database. For now I only have three: Report1,Report2,Report3.
> > > When I run the code below, the same report "Report1" keeps getting
> > > sent. Can someone please tell me what I'm doing wrong in the loop. For
> > > now, I only have three reports but by the end it will be about 150.
> > > Thanks in advance for any help,
>
> > > Private Sub Command0_Click()
> > > Dim db As database
> > > Dim rst As DAO.Recordset
> > > Dim x As Integer
> > > Dim Emailto As String
> > > Dim CC As String
> > > Dim RptName As String
>
> > > Set db = CurrentDb()
> > > Set rst = db.OpenRecordset("tbl_ReportList", dbOpenDynaset)
>
> > > With rst
> > > If Not (.EOF And .BOF) Then
> > > rst.MoveFirst
> > > Do Until rst.EOF
> > > For x = 1 To 140
> > > Emailto = DLookup("EmailtoName", "tbl_ReportList")
> > > CC = DLookup("CCName", "tbl_ReportList")
> > > RptName = DLookup("ReportName", "tbl_ReportList")
>
> > > DoCmd.SendObject acReport, RptName, "SnapshotFormat(*.snp)", _
> > > Emailto, CCto, "", "Attention Required Report", "", False,
> > > ""
> > > rst.MoveNext
> > > Next
> > > Loop
> > > End If
> > > End With
>
> > > rst.Close
> > > Set rst = Nothing
> > > Set db = Nothing
>
> > > End Sub- Hide quoted text -- Show quoted text -- Hide quoted text -- Show quoted text -
 >> Stay informed about: Looping through Records question 
Back to top
Login to vote
Douglas J. Steele

External


Since: Mar 14, 2004
Posts: 716



(Msg. 4) Posted: Wed Jan 24, 2007 4:56 pm
Post subject: Re: Looping through Records question [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Do you mean that RptName can contain a string like
"Report1,Report2,Report3"? If so, you really should read up on database
normalization: storing multiple values in a single field is a bad idea.

If RptName is a single report name, then you need to take advantage of the
fact that you've opened a recordset. Using DLookup is going to return the
same value every time.

The 3 lines

Emailto = DLookup("EmailtoName", "tbl_ReportList")
CC = DLookup("CCName", "tbl_ReportList")
RptName = DLookup("ReportName", "tbl_ReportList")

should be

Emailto = rst!EmailtoName
CC = rst!CCName
RptName = rst!ReportName


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"Kimberley" wrote in message

> Hi all,
> I have a table in access (tbl_ReportList) that has four fields (ID,
> Emailto, CC, and RptName). The email and CC fields both have e-mail
> addresses in them and the RptName field is a list of reports in the
> database. For now I only have three: Report1,Report2,Report3.
> When I run the code below, the same report "Report1" keeps getting
> sent. Can someone please tell me what I'm doing wrong in the loop. For
> now, I only have three reports but by the end it will be about 150.
> Thanks in advance for any help,
>
> Private Sub Command0_Click()
> Dim db As database
> Dim rst As DAO.Recordset
> Dim x As Integer
> Dim Emailto As String
> Dim CC As String
> Dim RptName As String
>
>
> Set db = CurrentDb()
> Set rst = db.OpenRecordset("tbl_ReportList", dbOpenDynaset)
>
>
> With rst
> If Not (.EOF And .BOF) Then
> rst.MoveFirst
> Do Until rst.EOF
> For x = 1 To 140
> Emailto = DLookup("EmailtoName", "tbl_ReportList")
> CC = DLookup("CCName", "tbl_ReportList")
> RptName = DLookup("ReportName", "tbl_ReportList")
>
>
> DoCmd.SendObject acReport, RptName, "SnapshotFormat(*.snp)", _
> Emailto, CCto, "", "Attention Required Report", "", False,
> ""
> rst.MoveNext
> Next
> Loop
> End If
> End With
>
>
> rst.Close
> Set rst = Nothing
> Set db = Nothing
>
>
> End Sub
>
 >> Stay informed about: Looping through Records question 
Back to top
Login to vote
Argusy

External


Since: Sep 19, 2003
Posts: 36



(Msg. 5) Posted: Mon Jan 29, 2007 2:11 pm
Post subject: Re: Looping through Records question [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Your answer is confusing!!

the word 'report1' IS a string of eight characters, yet you state
RptName cannot contain a string. (You've even defined it as a container
for strings)

Are you referring to the database 'ReportName' (is it string or numeric?)

Bugger, just had a callout - Douglas will continue with this

Argusy


Kimberley wrote:
> I also had a couple of things named incorrectly. But removing the
> DLOOKUP and using recordset worked perfectly.
>
> Thanks again for your help
>
> On Jan 24, 5:48 pm, "Kimberley" wrote:
>
>>Thanks for your reply. In answer to your question, RptName cannot
>>contain a string.
>>It contains only one report name. Each row in the table has the
>>following:
>>ID ReportName EmailtoName CCName
>>1 Report1 mbr....DeleteThis@public.com jjohn....DeleteThis@public.com
>>
>>What I want to do is send the Report1 to the EmailtoName and the
>>CCName listed in the same row. And then move on to the next one.
>>I followed your advice but I am still getting the same report (Report1)
>>over and over.
>>
>>On Jan 24, 4:56 pm, "Douglas J. Steele"
>>
>>
>>
>> wrote:
>>
>>>Do you mean that RptName can contain a string like
>>>"Report1,Report2,Report3"? If so, you really should read up on database
>>>normalization: storing multiple values in a single field is a bad idea.
>>
>>>If RptName is a single report name, then you need to take advantage of the
>>>fact that you've opened a recordset. Using DLookup is going to return the
>>>same value every time.
>>
>>>The 3 lines
>>
>>> Emailto = DLookup("EmailtoName", "tbl_ReportList")
>>> CC = DLookup("CCName", "tbl_ReportList")
>>> RptName = DLookup("ReportName", "tbl_ReportList")
>>
>>>should be
>>
>>> Emailto = rst!EmailtoName
>>> CC = rst!CCName
>>> RptName = rst!ReportName
>>
>>>--
>>>Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
>>>(no private e-mails, please)
>>
>>>"Kimberley" wrote in messagenews:1169658283.200316.142520@v45g2000cwv.googlegroups.com...
>>
>>>>Hi all,
>>>>I have a table in access (tbl_ReportList) that has four fields (ID,
>>>>Emailto, CC, and RptName). The email and CC fields both have e-mail
>>>>addresses in them and the RptName field is a list of reports in the
>>>>database. For now I only have three: Report1,Report2,Report3.
>>>>When I run the code below, the same report "Report1" keeps getting
>>>>sent. Can someone please tell me what I'm doing wrong in the loop. For
>>>>now, I only have three reports but by the end it will be about 150.
>>>>Thanks in advance for any help,
>>>
>>>>Private Sub Command0_Click()
>>>>Dim db As database
>>>>Dim rst As DAO.Recordset
>>>>Dim x As Integer
>>>>Dim Emailto As String
>>>>Dim CC As String
>>>>Dim RptName As String
>>>
>>>> Set db = CurrentDb()
>>>> Set rst = db.OpenRecordset("tbl_ReportList", dbOpenDynaset)
>>>
>>>> With rst
>>>> If Not (.EOF And .BOF) Then
>>>> rst.MoveFirst
>>>> Do Until rst.EOF
>>>> For x = 1 To 140
>>>> Emailto = DLookup("EmailtoName", "tbl_ReportList")
>>>> CC = DLookup("CCName", "tbl_ReportList")
>>>> RptName = DLookup("ReportName", "tbl_ReportList")
>>>
>>>> DoCmd.SendObject acReport, RptName, "SnapshotFormat(*.snp)", _
>>>> Emailto, CCto, "", "Attention Required Report", "", False,
>>>>""
>>>> rst.MoveNext
>>>> Next
>>>> Loop
>>>> End If
>>>> End With
>>>
>>>> rst.Close
>>>> Set rst = Nothing
>>>> Set db = Nothing
>>>
>>>>End Sub- Hide quoted text -- Show quoted text -- Hide quoted text -- Show quoted text -
>>>
>
 >> Stay informed about: Looping through Records question 
Back to top
Login to vote
Douglas J. Steele

External


Since: Mar 14, 2004
Posts: 716



(Msg. 6) Posted: Mon Jan 29, 2007 6:51 pm
Post subject: Re: Looping through Records question [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Sort of academic, since Kimberley reported it now "worked perfectly".

I believe that "RptName cannot contain a string" was a slightly misword
response to my question "Do you mean that RptName can contain a string like
'Report1,Report2,Report3'?" intended to mean that it wouldn't contain a
concatenated string.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"Argusy" wrote in message

> Your answer is confusing!!
>
> the word 'report1' IS a string of eight characters, yet you state RptName
> cannot contain a string. (You've even defined it as a container for
> strings)
>
> Are you referring to the database 'ReportName' (is it string or numeric?)
>
> Bugger, just had a callout - Douglas will continue with this
>
> Argusy
>
>
> Kimberley wrote:
>> I also had a couple of things named incorrectly. But removing the
>> DLOOKUP and using recordset worked perfectly.
>>
>> Thanks again for your help
>>
>> On Jan 24, 5:48 pm, "Kimberley" wrote:
>>
>>>Thanks for your reply. In answer to your question, RptName cannot
>>>contain a string.
>>>It contains only one report name. Each row in the table has the
>>>following:
>>>ID ReportName EmailtoName CCName
>>>1 Report1 mbr....RemoveThis@public.com jjohn....RemoveThis@public.com
>>>
>>>What I want to do is send the Report1 to the EmailtoName and the
>>>CCName listed in the same row. And then move on to the next one.
>>>I followed your advice but I am still getting the same report (Report1)
>>>over and over.
>>>
>>>On Jan 24, 4:56 pm, "Douglas J. Steele"
>>>
>>>
>>>
>>> wrote:
>>>
>>>>Do you mean that RptName can contain a string like
>>>>"Report1,Report2,Report3"? If so, you really should read up on database
>>>>normalization: storing multiple values in a single field is a bad idea.
>>>
>>>>If RptName is a single report name, then you need to take advantage of
>>>>the
>>>>fact that you've opened a recordset. Using DLookup is going to return
>>>>the
>>>>same value every time.
>>>
>>>>The 3 lines
>>>
>>>> Emailto = DLookup("EmailtoName", "tbl_ReportList")
>>>> CC = DLookup("CCName", "tbl_ReportList")
>>>> RptName = DLookup("ReportName", "tbl_ReportList")
>>>
>>>>should be
>>>
>>>> Emailto = rst!EmailtoName
>>>> CC = rst!CCName
>>>> RptName = rst!ReportName
>>>
>>>>--
>>>>Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
>>>>(no private e-mails, please)
>>>
>>>>"Kimberley" wrote in
>>>>messagenews:1169658283.200316.142520@v45g2000cwv.googlegroups.com...
>>>
>>>>>Hi all,
>>>>>I have a table in access (tbl_ReportList) that has four fields (ID,
>>>>>Emailto, CC, and RptName). The email and CC fields both have e-mail
>>>>>addresses in them and the RptName field is a list of reports in the
>>>>>database. For now I only have three: Report1,Report2,Report3.
>>>>>When I run the code below, the same report "Report1" keeps getting
>>>>>sent. Can someone please tell me what I'm doing wrong in the loop. For
>>>>>now, I only have three reports but by the end it will be about 150.
>>>>>Thanks in advance for any help,
>>>>
>>>>>Private Sub Command0_Click()
>>>>>Dim db As database
>>>>>Dim rst As DAO.Recordset
>>>>>Dim x As Integer
>>>>>Dim Emailto As String
>>>>>Dim CC As String
>>>>>Dim RptName As String
>>>>
>>>>> Set db = CurrentDb()
>>>>> Set rst = db.OpenRecordset("tbl_ReportList", dbOpenDynaset)
>>>>
>>>>> With rst
>>>>> If Not (.EOF And .BOF) Then
>>>>> rst.MoveFirst
>>>>> Do Until rst.EOF
>>>>> For x = 1 To 140
>>>>> Emailto = DLookup("EmailtoName", "tbl_ReportList")
>>>>> CC = DLookup("CCName", "tbl_ReportList")
>>>>> RptName = DLookup("ReportName", "tbl_ReportList")
>>>>
>>>>> DoCmd.SendObject acReport, RptName, "SnapshotFormat(*.snp)", _
>>>>> Emailto, CCto, "", "Attention Required Report", "", False,
>>>>>""
>>>>> rst.MoveNext
>>>>> Next
>>>>> Loop
>>>>> End If
>>>>> End With
>>>>
>>>>> rst.Close
>>>>> Set rst = Nothing
>>>>> Set db = Nothing
>>>>
>>>>>End Sub- Hide quoted text -- Show quoted text -- Hide quoted text --
>>>>>Show quoted text -
>>>>
>>
>
 >> Stay informed about: Looping through Records question 
Back to top
Login to vote
Argusy

External


Since: Sep 19, 2003
Posts: 36



(Msg. 7) Posted: Tue Jan 30, 2007 11:28 am
Post subject: Re: Looping through Records question [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Douglas J. Steele wrote:
> Sort of academic, since Kimberley reported it now "worked perfectly".
>
> I believe that "RptName cannot contain a string" was a slightly misword
> response to my question "Do you mean that RptName can contain a string like
> 'Report1,Report2,Report3'?" intended to mean that it wouldn't contain a
> concatenated string.
>

Yeah.. reading back I now get that

Actually, I've never used dlookup, so I was curious to the response to
Kimberley's query. I automatically 'corrected' her usage to rst!... in
my mind, and then left it alone, thinking "oh, yea, another approach"

Graham
 >> Stay informed about: Looping through Records question 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Deleting records from DAO recordset - [posted earlier in other group] Hi All, I'm using the following code to delete one or more records from a DAO recordset. The code is working but I was wondering if I need to Update the recordset with: rsDel.Update? Public Function DelRecs(Lstview As....

Posting linked records - I was brought up with dBase, and now need advice on how to post linked records using DAO & SQL. Though I could do a kludge for this, I want to know to do this simply and efficiently. I need to use DAO to post to a non-SQL system, where I calculate...

DAO Beginner Question - I need to have a program I am writing in Visual Basic 6.0 define a "cursor" (sorry for using Oracle terms.) then open a database, open a table, read a few records, and then close the table and database. The MSDN Library is a little confusin...

strange! vb6+access2002 - I have a mdb called treesy.mdb.There is a table,named transcipt with three fields:serial_no, eng,sound serial_no:1-10 (10 numbers) eng: 1.The movie has been on for 15 minutes, madam.@ 2.Oh, my god!@ It's 7:45 now!@ 3.Is Helen coming?@ It¡¯s 6:50 now.@..

Authentication Error??? - Ok so heres the code.. for some reason I kept getting the no permissions message, so I attempted to add the access workgroup file. Now I get the "Authentication Failed" message. This is a secure database. HELP.. I know I'm writing (adding) som...
   Database Forums (Home) -> Visual Basic -> DAO All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]