Selasa, 25 Oktober 2011

Re: [MS_AccessPros] My first Do Loop but with questions

 

oops!  meant to change this too...
With myset
   Do While Not .EOF

Warm Regards,
Crystal

 *
   (: have an awesome day :)
 *

________________________________
From: Crystal

Hi Jim, 

you need to specify where to get [First Name] and [Last Name] as you did with myset![E-mail Address]

to make things more efficient, I surrounded your corrected code with With...End With.  I also utilized + in case Last Name or E-mail Address is not filled out.  Also added cleanup code

you should avoid using special characters and spaces in names.  Underscore _ is ok.

'~~~~~~~~~~~~~~~~~~~~~
' more statements

With myset
   Do Until myset.EOF

       MyAddress = nz(![E-mail Address],"")
       MsgBox "My name and address" & " " & MyAddress

       MsgBox "My name and address is " _
          & ![First Name] & (" " + ![Last Name] ) & (" " + ![E-mail Address])

      .MoveNext
   Loop
End With

'cleanup code
on error resume next
if not myset is nothing then
   myset.close
   set myset = nothing
end if
set db = nothing

End Sub
'~~~~~~~~~~~~~~~~~~~~~

instead of MsgBox, try using Debug.Print

when you are running the code, you can look at the Immediate (debug) window instead of pressing OK all the time with a MsgBox

press Ctrl-G to Goto the debuG window

Warm Regards,
Crystal

 *
   (: have an awesome day :)
 *

________________________________
From: luvmymelody

Hello all,

I am practicing my first do loop and questioning why it took me so long to learn this. But here I am with a question.

I have the below code that I am trying to just get a message box to show first, last and address in the msgbox. If I use the first msgbox in the code it works great. The email addresses show up in the msgbox and all is great. But when I try to use the second msgbox in the code, I get the first name from the Contacts table and the email addresses from the tblTodaysBirthdays table cycle through with the same name. But the person's name in the msgbox is from the main table not the table the select statement is based on.

I have several tables involved in the question. The contacts table and the tblTodaysBirthdays. The latter is a table made from a make table query built every day based on the Contacts table.

Private Sub Command281_Click()
Dim mydb As DAO.Database
Dim myset As DAO.Recordset
Dim MyAddress As String

Set mydb = CurrentDb
Set myset = mydb.OpenRecordset("SELECT * FROM tblTodaysBirthdays where [E-mail Address] is not null")

Do Until myset.EOF

MyAddress = myset![E-mail Address]
'MsgBox "My name and address" & " " & MyAddress
MsgBox "My name and address is" & " " & [First Name] & " " & [Last Name] & " " & MyAddress
myset.MoveNext

Loop
End Sub

What am I missing here?

Thanks for the help

Jim Wagner

[Non-text portions of this message have been removed]

------------------------------------

Yahoo! Groups Links

[Non-text portions of this message have been removed]

__._,_.___
Recent Activity:
MARKETPLACE

Stay on top of your group activity without leaving the page you're on - Get the Yahoo! Toolbar now.

.

__,_._,___

Tidak ada komentar:

Posting Komentar