473,406 Members | 2,816 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,406 software developers and data experts.

Creating a DAO.Recordset for the first time....Help....

kcdoell
230 100+
Hello:

I am trying to create a DAO record set for the first time. I wanted to keep it simple, so I first wrote something to work for my Division field then I would expand on the code later. Below is what I have in my onClick event:

Expand|Select|Wrap|Line Numbers
  1. 'Checks to see if there are records for that given Division, Year, Month, Week Combo.
  2. 'If so tells the user to update
  3.  
  4. rstSQL = "SELECT tblStaticAllForecast.DivisionIDFK,  " & _
  5.             "FROM tblStaticAllForecast " & _
  6.             "WHERE ((tblStaticAllForecast.DivisionIDFK)='" & [Forms]![lock]![cboDivision] & "');"
  7.  
  8.     Dim rs As DAO.Recordset
  9.     Set rs = CurrentDb.OpenRecordset(rstSQL)
  10.     recordexists = rst.RecordCount
  11.  
  12.     If Nz(recordexists, 0) > 0 Then
  13.         MsgBox "The records that you are trying to lock already exists -- Please select another week or use the update feature."
  14.  
  15.         Else
  16.  
I am getting the following message when I execute:

Expand|Select|Wrap|Line Numbers
  1. The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect. (Error 3141)
  2.  
The error focuses on the
Expand|Select|Wrap|Line Numbers
  1.  Set rs = CurrentDb.OpenRecordset(rstSQL) 
. Since I am new at this can anybody see what I am missing? Any help or assistance would be greatly appreciated.

Thanks,

Keith.
Mar 26 '08 #1
4 1778
kcdoell
230 100+
Hello again:

I thought I needed to write in Dim rstSQL As String, so I included it below:

Expand|Select|Wrap|Line Numbers
  1. Dim rstSQL As String
  2.  
  3. rstSQL = "SELECT tblStaticAllForecast.DivisionIDFK,  " & _
  4.             "FROM tblStaticAllForecast " & _
  5.             "WHERE ((tblStaticAllForecast.DivisionIDFK)='" & [Forms]![lock]![cboDivision] & "');"
  6.  
  7.     Dim rs As DAO.Recordset
  8.     Set rs = CurrentDb.OpenRecordset(rstSQL)
  9.     recordexists = rst.RecordCount
  10.  
  11.     If Nz(recordexists, 0) > 0 Then
  12.         MsgBox "The records that you are trying to lock already exists -- Please select another week or use the update feature."
  13.  
  14.         Else
  15.  
But that did not change the error message or where it is pointing to. Not sure if that was needed.

Any help would be great

Thanks,

Keith.
Mar 26 '08 #2
kcdoell
230 100+
Hello:

I was thinking that my problem was in my SQL so I changed it to the following:

Expand|Select|Wrap|Line Numbers
  1. Dim rst As DAO.Recordset
  2. Dim LockSQL As String
  3.  
  4.     LockSQL = "SELECT * FROM tblStaticAllForecast WHERE DivisionIDFK = '" & _
  5.     Val(Me.cboDivision.Value) & "'"
  6.  
  7.     Set rst = CurrentDb.OpenRecordset(LockSQL)
  8.     recordexists = rst.RecordCount
  9.  
  10.     If Nz(recordexists, 0) > 0 Then
  11.         MsgBox "The records that you are trying to lock already exists -- Please select another week or use the update feature."
  12.  
  13.         Else
  14.  
Now I am getting the following error message:

Expand|Select|Wrap|Line Numbers
  1. Data type mismatch in criteria expression. (Error 3464)
  2. The criteria expression in a Find method is attempting to compare a field with a value whose data type does not match the field’s data type.
  3.  
Am I going down the right road on this? I eventually want to expand on the where statement but at this point I am at a dead stop.

Any ideas would be a great help.

Thanks,

Keith.
Mar 26 '08 #3
kcdoell
230 100+
I figured it out. The problem was in my SQL statement. In the end I wrote my other "where" statements. Below was my solution for those that stumble across this issue.

Expand|Select|Wrap|Line Numbers
  1. 'Checks to see if there are records for that given Division, Year, Month, Week Combo.
  2. 'If so tells the user to update
  3.  
  4. Dim rst As DAO.Recordset
  5. Dim LockSQL As String
  6.  
  7.   LockSQL = "SELECT * FROM tblStaticAllForecast WHERE" & _
  8.         " DivisionIDFK = " & Val(Me.cboDivision.Value) & _
  9.         " And YearID = '" & Val(Me.CboMonth.Value) & "'" & _
  10.         " And MonthID = '" & Val(Me.CboYear.Value) & "'" & _
  11.         " And FWeek = '" & Val(Me.cboWeek.Value) & "'"
  12.  
  13.     Set rst = CurrentDb.OpenRecordset(LockSQL)
  14.     recordexists = rst.RecordCount
  15.  
  16.     If Nz(recordexists, 0) > 0 Then
  17.                MsgBox "The records that you are trying to lock already exists. " & _
  18.                     "Please select another week or use the update feature."
  19.  
  20.         Else
  21.  
P.S. Three of my controls in my "where" statement were set to text on my table, hence the coding....

Best regards,

Keith.
Mar 26 '08 #4
kcdoell
230 100+
Correction in my code:

Expand|Select|Wrap|Line Numbers
  1. 'Checks to see if there are records for that given Division, Year, Month, Week Combo.
  2. 'If so tells the user to update
  3.  
  4. Dim rst As DAO.Recordset
  5. Dim LockSQL As String
  6.  
  7.   LockSQL = "SELECT * FROM tblStaticAllForecast WHERE" & _
  8.         " DivisionIDFK = " & Val(Me.cboDivision.Value) & _
  9.         " And YearID = '" & Val(Me.CboYear.Value) & "'" & _
  10.         " And MonthID = '" & Val(Me.CboMonth.Value) & "'" & _
  11.         " And FWeek = '" & Val(Me.cboWeek.Value) & "'"
  12.  
  13.     Set rst = CurrentDb.OpenRecordset(LockSQL)
  14.     recordexists = rst.RecordCount
  15.  
  16.     If Nz(recordexists, 0) > 0 Then
  17.                MsgBox "The records that you are trying to lock already exists. " & _
  18.                     "Please select another week or use the update feature."
  19.  
  20.         Else
  21.  
Month and year were miss transposed.........
Mar 27 '08 #5

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

Similar topics

8
by: Dima Protchenko | last post by:
Hi, guys. Please help if you know something about this. Error: ADODB.Recordset error '800a0e78' Operation is not allowed when the object is closed. line: if not rs.EOF then (from the code...
17
by: Ange T | last post by:
Hi there, I'm having pain with the VB behind an Access form. The form is used to create reports in Excel based on the details entered in the form. This has always worked without error on my...
2
by: Chris via AccessMonster.com | last post by:
I have done something like this a million years ago my developer skills have diminished to nothing but now I am at a new job trying to regroup what I lost. This one came across my desk recently. I...
2
by: Jozef | last post by:
Hello, I'm trying to create a central function that runs a connection to an SQL Server database. The connection etc works, but when I try to call it, I get an error saying "Runtime-Error 91:...
36
by: kjvt | last post by:
Based on a prior posting, I've written a function to convert a recordset to a dataview. The first call to the function for a given recordset works perfectly, but the second call always returns a...
0
by: MG | last post by:
Hello all, Perhaps you can help me. I have a com object which I converted from VB6 to VB.NET. I am using this com object with other .Net applications without any problem. However, I am now trying...
10
by: shubha.sunkada | last post by:
Hi, I have a recordset connection in asp that I am using to search records.If I use the client side cursorlocation (rs.cursorlocation=3) then it takes really long to return back the records due...
6
by: Oko | last post by:
I'm currently developing an MS Access Data Project (.adp) in MS Access 2002. One of the reports within the DB uses data that is Dynamic and cannot be stored on the SQL Server. To resolve this, I...
2
by: wallconor | last post by:
Hi, I am having a problem using Dreamweaver CS3 standard recordset paging behavior. It doesn’t seem to work when I pass parameter values from a FORM on my search page, to the recordset on my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.