G
Guest
I named the module something entirely different.
No, I am running the code within VB. I guess that was my main question. I
have it in a "Select" event. I use the SQL statement that the query
generates and I put it in VB after: myRecordset.Open
My Access book says, "You don't have to base a recordset on a single table.
You can base it on a query. But you can't use the query's name in the
myRecordset.Open statement because only table names are allowed." It then
says to get the SQL statement from the query and paste it into VB after the
myRecordset.Open and inbetween the double quotes.
So that's what I did. But then I get that error. I know I am totally
confused here, so I hope I'm not confusing you. One more thing: I am not
putting a user-defined function into the Access query. The query works
perfectly. It generates the person's age by year, month and day. I just
need to translate that into VB so that it will populate the text box.
Thanks again!
No, I am running the code within VB. I guess that was my main question. I
have it in a "Select" event. I use the SQL statement that the query
generates and I put it in VB after: myRecordset.Open
My Access book says, "You don't have to base a recordset on a single table.
You can base it on a query. But you can't use the query's name in the
myRecordset.Open statement because only table names are allowed." It then
says to get the SQL statement from the query and paste it into VB after the
myRecordset.Open and inbetween the double quotes.
So that's what I did. But then I get that error. I know I am totally
confused here, so I hope I'm not confusing you. One more thing: I am not
putting a user-defined function into the Access query. The query works
perfectly. It generates the person's age by year, month and day. I just
need to translate that into VB so that it will populate the text box.
Thanks again!
Douglas J. Steele said:When you copied the code for Diff2Dates into your application, what did you
name the module? If you named the module Diff2Dates, rename it: modules
can't be named the same as functions or subs in them.
I'm assuming you're actually running this code from within Access, not from
a VB program. You can't put user-defined functions into Access queries if
you're running them from outside of Access.
--
Doug Steele, Microsoft Access MVP
(no private e-mails, please)
Lynn said:Doug:
Thank you so much for getting back to me. I spent all day yesterday
reading
about Access queries. I program in VB6 and have very little experience in
Access. Here is my code:
Dim myConnection As ADODB.Connection
Set myConnection = New Connection
Dim myRecordset As New ADODB.Recordset
myRecordset.ActiveConnection = myConnection
' Open PatientInfo Query
myRecordset.Open "SELECT PatientInfo.PatientID, PatientInfo.Birthdate,
Diff2Dates('ymd',[Birthdate],Now()) AS Age FROM PatientInfo", dBase,
adOpenDynamic, adLockOptimistic
myRecordset.Filter = "(PatientID) like '" & strPatientID & "*'"
frmPatientInfo.txtAge.Text = rs![Age]
myRecordset.Close
I have the "Open" statement on one line. I set a break at rs![Age] and it
gives me that "Item cannot be found..." error. Can you please tell me
what I
am doing wrong? I'm curious, how does VB know what query to look in? I
see
where it refers to the table, but not the query. Any help would be
greatly
appreciated!
Lynn
Douglas J. Steele said:You'll need to post the code you're trying to use.
--
Doug Steele, Microsoft Access MVP
(no private e-mails, please)
My question is similar but it has to do with connecting the database
with
Visual Basic. I built a query to determine a person's age per the
above
instructions. It works perfectly (thank you). I copied the SQL code
and
put it in my VB code after "myRecordset.open." I want it to fill the
textbox
(in VB) with the person's age. Now it gives me the error: "Item
cannot
be
found in the collection corresponding to the recordset." I have other
databases that work fine in VB and fill out textboxes just fine. I
triple-checked the spelling of the field names, etc., and they all
match.
Can anyone help?
Thanks,
Lynn
:
in message:
Hi Jeff and Doug, this works perfectly! Thank you SO much for your
help.
You're welcome, glad we could help.
--
Jeff Conrad
Access Junkie - MVP
http://home.bendbroadband.com/conradsystems/accessjunkie.html
http://www.access.qbuilt.com/html/articles.html