My Assistant
![]() ![]() |
|
|
Sep 21 2007, 01:52 PM
Post
#1
|
|
|
UtterAccess Member Posts: 44 |
I am trying to open a form based on a query. If the query is EOF open the form on a new record. If the query finds a resulf open the form at that record. Here is my code.
Private Sub Dim Key Dim strSQL Dim db As DAO.Database '(where I get the error) Dim qdf As DAO.QueryDef Set db = CurrentDb() Set qdf = db.QueryDefs(strSQL) Key = [Forms]![PMSMain]![ListProperties].Value strSQL = "SELECT AdditionInfo.Key FROM AdditionInfo WHERE(AdditionInfo.Key) = " & Key & "" Set db = CurrentDb() Set qdf = db.QueryDefs(strSQL) qdf.SQL = strSQL If EOF(qdf) = True Then DoCmd.OpenForm "FrmOwnInfo", acNormal, , , acFormAdd, acWindowNormal Forms!FrmOwnInfo!Key = Key Else DoCmd.OpenForm "FrmOwnInfo", acNormal, , "Key=" & Key, acFormEdit, acWindowNormal End If End Sub |
|
|
|
Sep 21 2007, 01:54 PM
Post
#2
|
|
|
VIP Emeritus Posts: 1,750 From: The Great White North |
Hi,
Have you added the Microsoft DAO Library Reference? If not, go to Tools->References and then scroll down to it. |
|
|
|
Sep 21 2007, 01:54 PM
Post
#3
|
|
|
Utterly Banned Posts: 7,038 |
In Access 2002, DAO was not the default - ADO was, so go open the Visual Basic Integrated Development Environment (IDE) Window and go to Tools > References and make sure that Microsoft DAO is checked.
|
|
|
|
Sep 21 2007, 01:55 PM
Post
#4
|
|
|
Utterly Banned Posts: 7,038 |
Hmm - seems we posted the same thing at the same time (IMG:http://www.utteraccess.com/forum/style_emoticons/default/yayhandclap.gif)
|
|
|
|
Sep 21 2007, 02:19 PM
Post
#5
|
|
|
UtterAccess Member Posts: 44 |
And you were BOTH right!!! But now I get a Type Mismatch error.
If EOF(qdf) = True Then '(I get the error here) DoCmd.OpenForm "FrmOwnInfo", acNormal, , , acFormAdd, acWindowNormal Forms!FrmOwnInfo!Key = Key Else DoCmd.OpenForm "FrmOwnInfo", acNormal, , "Key=" & Key, acFormEdit, acWindowNormal End If |
|
|
|
Sep 21 2007, 02:23 PM
Post
#6
|
|
|
VIP Emeritus Posts: 1,750 From: The Great White North |
Hi,
EOF isnt a function that you can call and pass a query to.. Are you trying to see if there are any records returned by that query? You can use the recordcoutn property for that, or even skip the whole thing and use a DCount.. |
|
|
|
Sep 21 2007, 03:43 PM
Post
#7
|
|
|
UtterAccess Member Posts: 44 |
DCount worked great!!
Thank you Adam. Keith |
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 22nd May 2013 - 03:48 AM |