Haslett, Andrew
andrew.haslett at ilc.gov.au
Tue Nov 4 22:57:23 CST 2003
1) You should try to dim your variables with its library, especially in
regard to databases and recordsets.
2) You need to escape your variables from within your SQL string.
3) If all you want is a count of records, there's no need to retrieve an
entire recordset. Use DCOUNT function or SELECT COUNT.
4) You can use ME instead of the full form name, if you are running this
code from an event of the same form,
So to fix the intital problem:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.
Dim db DAO.As Database
Dim rs As DAO.Recordset
Dim strSQL As String
Dim x As Long
Set db = CurrentDb()
strSQL = "SELECT tblAssesmentResults.AssesmentResultID,
tblAssesmentResults.ResultID _
FROM tblAssesmentResults _
WHERE tblAssesmentResults.ResultID = " &
[Forms]![frmAssesments]![txtResultID])) & ";"
Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot)
With rs
'If Not .EOF Then
x = rs.RecordCount
MsgBox x
'End If
.Close
End With
Set rs = Nothing
db.Close
Set db = Nothing
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
A better method:
*********************************************************
Dim x as long
x = DCOUNT("*","tblAssesmentResults","ResultID = " & me.txtResultID)
msgbox x
*********************************************************
Cheers,
Andrew
PS. You spelt Assessment wrong ;=)
-----Original Message-----
From: Darren DICK [mailto:d.dick at uws.edu.au]
Sent: Wednesday, 5 November 2003 2:37 PM
To: AccessD List
Subject: [AccessD] A2K: Too Few Paramaters. Expected 1
Hello all
Can anyone tell me why I am getting the dreaded Too Few Paramaters blah blah
blah error message when
I run the code below?? The code is almast exact of something else that is
running quite well on the same form.
Many thanks
Darren
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.
Dim db As Database
Dim rs As Recordset
Dim strSQL As String
Dim x As Long
Set db = CurrentDb()
strSQL = "SELECT tblAssesmentResults.AssesmentResultID,
tblAssesmentResults.ResultID FROM tblAssesmentResults WHERE
(((tblAssesmentResults.ResultID)=[Forms]![frmAssesments]![txtResultID]));"
Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot)
With rs
'If Not .EOF Then
x = rs.RecordCount
MsgBox x
'End If
.Close
End With
Set rs = Nothing
db.Close
Set db = Nothing
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
IMPORTANT - PLEASE READ ********************
This email and any files transmitted with it are confidential and may
contain information protected by law from disclosure.
If you have received this message in error, please notify the sender
immediately and delete this email from your system.
No warranty is given that this email or files, if attached to this
email, are free from computer viruses or other defects. They
are provided on the basis the user assumes all responsibility for
loss, damage or consequence resulting directly or indirectly from
their use, whether caused by the negligence of the sender or not.