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: -
'Checks to see if there are records for that given Division, Year, Month, Week Combo.
-
'If so tells the user to update
-
-
rstSQL = "SELECT tblStaticAllForecast.DivisionIDFK, " & _
-
"FROM tblStaticAllForecast " & _
-
"WHERE ((tblStaticAllForecast.DivisionIDFK)='" & [Forms]![lock]![cboDivision] & "');"
-
-
Dim rs As DAO.Recordset
-
Set rs = CurrentDb.OpenRecordset(rstSQL)
-
recordexists = rst.RecordCount
-
-
If Nz(recordexists, 0) > 0 Then
-
MsgBox "The records that you are trying to lock already exists -- Please select another week or use the update feature."
-
-
Else
-
I am getting the following message when I execute: -
The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect. (Error 3141)
-
The error focuses on the - 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.
4 1778
Hello again:
I thought I needed to write in Dim rstSQL As String, so I included it below: -
Dim rstSQL As String
-
-
rstSQL = "SELECT tblStaticAllForecast.DivisionIDFK, " & _
-
"FROM tblStaticAllForecast " & _
-
"WHERE ((tblStaticAllForecast.DivisionIDFK)='" & [Forms]![lock]![cboDivision] & "');"
-
-
Dim rs As DAO.Recordset
-
Set rs = CurrentDb.OpenRecordset(rstSQL)
-
recordexists = rst.RecordCount
-
-
If Nz(recordexists, 0) > 0 Then
-
MsgBox "The records that you are trying to lock already exists -- Please select another week or use the update feature."
-
-
Else
-
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.
Hello:
I was thinking that my problem was in my SQL so I changed it to the following: -
Dim rst As DAO.Recordset
-
Dim LockSQL As String
-
-
LockSQL = "SELECT * FROM tblStaticAllForecast WHERE DivisionIDFK = '" & _
-
Val(Me.cboDivision.Value) & "'"
-
-
Set rst = CurrentDb.OpenRecordset(LockSQL)
-
recordexists = rst.RecordCount
-
-
If Nz(recordexists, 0) > 0 Then
-
MsgBox "The records that you are trying to lock already exists -- Please select another week or use the update feature."
-
-
Else
-
Now I am getting the following error message: -
Data type mismatch in criteria expression. (Error 3464)
-
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.
-
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.
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. -
'Checks to see if there are records for that given Division, Year, Month, Week Combo.
-
'If so tells the user to update
-
-
Dim rst As DAO.Recordset
-
Dim LockSQL As String
-
-
LockSQL = "SELECT * FROM tblStaticAllForecast WHERE" & _
-
" DivisionIDFK = " & Val(Me.cboDivision.Value) & _
-
" And YearID = '" & Val(Me.CboMonth.Value) & "'" & _
-
" And MonthID = '" & Val(Me.CboYear.Value) & "'" & _
-
" And FWeek = '" & Val(Me.cboWeek.Value) & "'"
-
-
Set rst = CurrentDb.OpenRecordset(LockSQL)
-
recordexists = rst.RecordCount
-
-
If Nz(recordexists, 0) > 0 Then
-
MsgBox "The records that you are trying to lock already exists. " & _
-
"Please select another week or use the update feature."
-
-
Else
-
P.S. Three of my controls in my "where" statement were set to text on my table, hence the coding....
Best regards,
Keith.
Correction in my code: -
'Checks to see if there are records for that given Division, Year, Month, Week Combo.
-
'If so tells the user to update
-
-
Dim rst As DAO.Recordset
-
Dim LockSQL As String
-
-
LockSQL = "SELECT * FROM tblStaticAllForecast WHERE" & _
-
" DivisionIDFK = " & Val(Me.cboDivision.Value) & _
-
" And YearID = '" & Val(Me.CboYear.Value) & "'" & _
-
" And MonthID = '" & Val(Me.CboMonth.Value) & "'" & _
-
" And FWeek = '" & Val(Me.cboWeek.Value) & "'"
-
-
Set rst = CurrentDb.OpenRecordset(LockSQL)
-
recordexists = rst.RecordCount
-
-
If Nz(recordexists, 0) > 0 Then
-
MsgBox "The records that you are trying to lock already exists. " & _
-
"Please select another week or use the update feature."
-
-
Else
-
Month and year were miss transposed.........
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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:...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |