473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Dcount getting runtime error '2471'

46
Bookings ID is number
ID is autonumber
Error says:
Run-Time error '2471':
The expression you entered as a query parameter produced this error: '[Bookings ID]'

Expand|Select|Wrap|Line Numbers
  1. If DCount("[Click ID]", "Access Click log", "[Bookings ID] = " & Forms![Roll Out CRM]![Royal Rollout AM Routes]![ID]) = 0 Then
Thank you for the help!
Vasago
Apr 18 '14 #1

✓ answered by zmbd

Look at two things:

-- Open the table "Access Click log" where[Bookings ID] is located.
Check that the field name is spelled correctly between the code and the table.

-- Check the type cast of the [Bookings ID] field, I suspect it is set to "text" not numeric as you are expecting.

8 6346
Rabbit
12,516 Expert Mod 8TB
If booking id is a string, you will need to surround the value you're looking for in quotes.
Apr 18 '14 #2
Vasago
46
Booking ID's type is a number along with ID
Apr 18 '14 #3
Rabbit
12,516 Expert Mod 8TB
Then you will need to post the full exact error message.
Apr 18 '14 #4
zmbd
5,501 Expert Mod 4TB
- The string theory:
You've stumbled upon one of my pet peeves by building the criteria string within the command - and it's not your fault because that's how a majority of examples show how to use the command.
Instead I suggest that you build the string first and then use the string in the command. Why you might ask, because you can then check how the string is actually resolving; thus, making troubleshooting the code so much easier as most of the time the issue is with something missing or not resolving properly/as expected within your string.
So to use your code:

Expand|Select|Wrap|Line Numbers
  1. '>The following is air code; thus, not tested and may require more effort to operate properly
  2. '
  3.     DIM strSQL as string
  4.     Dim intCount As Integer
  5. '
  6. '
  7.     strSQL = "[Bookings ID] = " & _
  8.         Forms![Roll Out CRM]![Royal Rollout AM Routes]![ID]
  9. '
  10. 'now you can insert a debug print here for troubleshooting
  11. ' - press <ctrl><g> to open the immediate window
  12. ' - you can now cut and paste this information for review!
  13. '
  14. debug.print "Your criteria = " & strSQL
  15. '
  16. 'now use the string in your code:
  17.     intCount= DCount("[Click ID]", "Access Click log", strSQL)
  18. debug.print "Your Count= " & intCount
  19. '
  20. 'Note: I didn't return the count within the IF...THEN...
  21. 'once again because troubleshooting the code is not easily 
  22. 'done when the function returns within another 
  23. 'function/statement.
  24. '
  25. '
  26.     if intCount = 0 then
  27.         'the remaining code
  28.     end if
  29. '
  30. '
If you will make these little changes and post back the resolved string we can help you tweak the code.

When posting errors:
Please post the EXACT title, number, and text of the error message. Please do not alter, omit, nor abreviate the information provided in the error message. ALSO indicate on which line of the code the error occurs and provide enough code so that we have the context of the commands used.
Apr 18 '14 #5
Vasago
46
ZMBD,

I can't thank you enough for you time, education and knowledge. I have included the code below. My debug print for strSQL is Your criteria = Bookings ID = 2110. This is the correct Booking ID number.

Error Code on line 9:
Run-time error '2471':
The expression you entered as a query parameter produced this error: '[Bookings ID]'

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_AfterInsert()
  2. Dim db As Recordset
  3. Dim strSQL As String
  4. Dim intCount As Integer
  5.  
  6.     strSQL = "[Bookings ID] = " & _
  7.         Forms![Roll Out CRM]![Royal Roll out Field Trips]![ID]
  8. Debug.Print "Your criteria = " & strSQL
  9.     intCount = DCount("[Click ID]", "Access Click log", strSQL)
  10. Debug.Print "Your Count= " & intCount
  11. If intCount = 0 Then
  12. Set db = CurrentDb.OpenRecordset("SELECT * FROM [Access click Log]")
  13. db.AddNew
  14. db![Booking ID] = ID
  15. db.Update
  16. End If
Apr 22 '14 #6
Vasago
46
Zmbd,

I can't thank you enough for you time, lesson, and knowledge. My debug print for strSQL is Your criteria = [Bookings ID] = 2113. This is the correct Bookings ID.

I am getting the error below on line 9.

Error:
Run-time error '2471':
The expression you entered as a query parameter produced this error: '[Bookings ID]'

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_AfterInsert()
  2. Dim db As Recordset
  3. Dim strSQL As String
  4. Dim intCount As Integer
  5.  
  6.     strSQL = "[Bookings ID] = " & _
  7.         Forms![Roll Out CRM]![Royal Roll out Field Trips]![ID]
  8. Debug.Print "Your criteria = " & strSQL
  9.     intCount = DCount("[Click ID]", "Access Click log", strSQL)
  10. Debug.Print "Your Count= " & intCount
  11. If intCount = 0 Then
  12. Set db = CurrentDb.OpenRecordset("SELECT * FROM [Access click Log]")
  13. db.AddNew
  14. db![Booking ID] = ID
  15. db.Update
  16. End If
Apr 22 '14 #7
zmbd
5,501 Expert Mod 4TB
Look at two things:

-- Open the table "Access Click log" where[Bookings ID] is located.
Check that the field name is spelled correctly between the code and the table.

-- Check the type cast of the [Bookings ID] field, I suspect it is set to "text" not numeric as you are expecting.
Apr 22 '14 #8
Vasago
46
ZMBD,

Thank you again for your help. Problem is solved and I feel extremely embarrassed. [Bookings ID] is suppose to be [Booking ID].

Thank you,
Vasago
Apr 23 '14 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Bill Patel | last post by:
I am getting Runtime error on line 50. Please Help. Thank You Bill 1 <%@ Page Language="VB" %> 2 <%@ import Namespace="System.Data" %> 3 <%@ import Namespace="System.Data.SqlClient"...
4
by: Pat | last post by:
In my Web.config i have :- <customErrors mode="On" defaultRedirect="genericerror.htm"> <error statusCode="404" redirect="pagenotfound.aspx"/> </customErrors to get page not found error but...
1
by: joswell | last post by:
Need a little help please! I am getting runtime error 3001 at oRS.filter = ("RM TYP = '" & cell.Text & "'") Private Sub CommandButton5_Click() Application.ScreenUpdating =...
7
by: ruvi | last post by:
I am getting runtime error 3021 - Either EOF or BOF is true or the current record has been deleted..... I have 2 combo boxes in a form- One for the client and the other for the project. When the...
7
by: opie | last post by:
I created this program on Vista using VB 6.0 with Access as the DB. When I created the executable and was trying to use it, on a XP machine, it gave me two issues. The first problem was it was...
1
by: Lauren Dobson | last post by:
This database was working days ago, outputting a vocabulary list into a word document. Any idea why I'm getting runtime error 3010? I just switched from Windows XP to Windows 7 but I'm still using...
1
by: creation | last post by:
$b= 1; while($b) { $a = <>; if($a eq 42) break; else { print $a; }
1
by: mishika | last post by:
Q: getting runtime error 52 bas file name or number D:Public Function gf_ChkMkDir(iDirPath As String, iDirName As String) As Boolean Dim MyPath As String gf_ChkMkDir = False MyPath =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.