kpark_67
Sep 21 2007, 01:52 PM
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
adamsherring
Sep 21 2007, 01:54 PM
Hi,
Have you added the Microsoft DAO Library Reference?
If not, go to Tools->References and then scroll down to it.
Bob_L
Sep 21 2007, 01:54 PM
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.
Bob_L
Sep 21 2007, 01:55 PM
Hmm - seems we posted the same thing at the same time
kpark_67
Sep 21 2007, 02:19 PM
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
adamsherring
Sep 21 2007, 02:23 PM
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..
kpark_67
Sep 21 2007, 03:43 PM
DCount worked great!!
Thank you Adam.
Keith
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.