473,432 Members | 1,611 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,432 software developers and data experts.

you cancelled prev. operation error

i have a form that is used to enter 4 values in a tblmonthlyunits. they are:
salesperson (text), monthandyear (date in the format mmm-yyyy), department
(text) and units (gen. number). i have a search button on this form that
opens a 2nd form, formsearchmontlyunits, where a user would enter 1 or more
values to do a search with, then those values are formed into an sql that is
used to filter the first form. my problem is that i didn't write this code (i
do understand it, but i seemingly can't debug it). now that i've change a
few things in the forms, the code doesn't work.

it gets hung up at the dlookup function where it is supposed to verify that
there are records present that meet the criteria. my thought is the problem
is the date format. i did a msgbox for the where on the sql and got (date) =
10/01/2005 even though my entry on the search form was oct-2005 (this is how
the records are stored in the table). here's the code:

Private Sub cmdEdit_Click()
Dim strWhere As String
Dim strF As String

strWhere = BuildWhere

' the form is already open...so we set the filter..not the "where"

' however, BEFORE we do this, lets make sure some reocrds match!!

If DCount("*", "tblsoldunits", strWhere) = 0 Then

MsgBox "no records found", vbExclamation, "no match"

Else

' got some rocords...lets filter

strF = "formmonthlyunits"
Forms(strF).Filter = strWhere
Forms(strF).FilterOn = True

DoCmd.Close acForm, Me.Name

End If
End Sub

Function CheckFields()

' check for required fields
' returns false if required fields missing
If IsNull(Me.tboxmonthandyear) = True Then

MsgBox "Month and Year are required", vbExclamation, "Date required"
Me.tboxmonthandyear.SetFocus
Exit Function

End If

End Function

Function BuildWhere() As String
Dim strTemp As String
Dim strWhere As String
Dim strField As String
Dim strControl As String

If (IsNull(Me.tboxmonthandyear) = False) Then
strWhere = "([Date] = " & "#" & (Me.tboxmonthandyear) & "#)"
End If

Call AddWhere("cboxSalesperson", "Salesperson", strWhere)

Call AddWhere("cboxdepartment", "Department", strWhere)

BuildWhere = strWhere
End Function

Sub AddWhere(strControl As String, strField As String, strWhere As String)
If IsNull(Me(strControl)) = False Then

If strWhere <> "" Then
strWhere = strWhere & " and "
End If

strWhere = strWhere & "(" & strField & " = " & """ & "(Me(strControl).
Value) & ")" & """

End If

End Sub

thanks for looking.

--
Message posted via http://www.accessmonster.com
Nov 28 '05 #1
3 1221
The textbox for the date is called txtMonthAndYear. Is this a full date or
just the month and year? What value is in the field? What is the data type
of the field?

Also, have you placed a Debug.Print line in the code to have the strWhere
clause print to the immediate window to make sure that your where strings
looks the way you want it to? Before the line

BuildWhere = strWhere

add the line

Debug.Print strWhere

--
Wayne Morgan
MS Access MVP
"ka******@comcast.net via AccessMonster.com" <u15580@uwe> wrote in message
news:580c069c08285@uwe...
i have a form that is used to enter 4 values in a tblmonthlyunits. they
are:
salesperson (text), monthandyear (date in the format mmm-yyyy), department
(text) and units (gen. number). i have a search button on this form that
opens a 2nd form, formsearchmontlyunits, where a user would enter 1 or
more
values to do a search with, then those values are formed into an sql that
is
used to filter the first form. my problem is that i didn't write this code
(i
do understand it, but i seemingly can't debug it). now that i've change a
few things in the forms, the code doesn't work.

it gets hung up at the dlookup function where it is supposed to verify
that
there are records present that meet the criteria. my thought is the
problem
is the date format. i did a msgbox for the where on the sql and got
(date) =
10/01/2005 even though my entry on the search form was oct-2005 (this is
how
the records are stored in the table). here's the code:

Private Sub cmdEdit_Click()
Dim strWhere As String
Dim strF As String

strWhere = BuildWhere

' the form is already open...so we set the filter..not the "where"

' however, BEFORE we do this, lets make sure some reocrds match!!

If DCount("*", "tblsoldunits", strWhere) = 0 Then

MsgBox "no records found", vbExclamation, "no match"

Else

' got some rocords...lets filter

strF = "formmonthlyunits"
Forms(strF).Filter = strWhere
Forms(strF).FilterOn = True

DoCmd.Close acForm, Me.Name

End If
End Sub

Function CheckFields()

' check for required fields
' returns false if required fields missing
If IsNull(Me.tboxmonthandyear) = True Then

MsgBox "Month and Year are required", vbExclamation, "Date required"
Me.tboxmonthandyear.SetFocus
Exit Function

End If

End Function

Function BuildWhere() As String
Dim strTemp As String
Dim strWhere As String
Dim strField As String
Dim strControl As String

If (IsNull(Me.tboxmonthandyear) = False) Then
strWhere = "([Date] = " & "#" & (Me.tboxmonthandyear) & "#)"
End If

Call AddWhere("cboxSalesperson", "Salesperson", strWhere)

Call AddWhere("cboxdepartment", "Department", strWhere)

BuildWhere = strWhere
End Function

Sub AddWhere(strControl As String, strField As String, strWhere As String)
If IsNull(Me(strControl)) = False Then

If strWhere <> "" Then
strWhere = strWhere & " and "
End If

strWhere = strWhere & "(" & strField & " = " & """ &
"(Me(strControl).
Value) & ")" & """

End If

End Sub

thanks for looking.

--
Message posted via http://www.accessmonster.com

Nov 28 '05 #2
tboxmonthandyear is just the month and the year. format is mmm-yyyy. if i
type in 10/2005 in this field it will automatically change it to oct-2005.
this is as desired. the data type of the field is date/time.

the debug.print line came up with this:

([Date] = #10/1/2005#)

now, when i build a query from tblsoldunits in design view, using 10-01-05 as
a criteria, it WILL filter the rest of the records out. the sql looks like
this:

SELECT tblsoldunits.salesperson, tblsoldunits.monthandyear, tblsoldunits.
department, tblsoldunits.units
FROM tblsoldunits
WHERE (((tblsoldunits.monthandyear)=#10/1/2005#));

(btw... i want to be clear and say that the actual name of this table is
tblsoldunits. if i refer to it as tblmonthlyunits it's because it has
changed over the last few weeks as a result of being re-done so many times.
this is just my foggy brain trying to cope with the fact that most of my
tables/forms/queries have been renamed recently and i cling to the old ones.)

Wayne Morgan wrote:
The textbox for the date is called txtMonthAndYear. Is this a full date or
just the month and year? What value is in the field? What is the data type
of the field?

Also, have you placed a Debug.Print line in the code to have the strWhere
clause print to the immediate window to make sure that your where strings
looks the way you want it to? Before the line

BuildWhere = strWhere

add the line

Debug.Print strWhere
i have a form that is used to enter 4 values in a tblmonthlyunits. they
are:

[quoted text clipped - 97 lines]

thanks for looking.


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200511/1
Nov 28 '05 #3
sigh.. nevermind. i found the problem. i had this line:

strWhere = "([Date] = " & "#" & (Me.tboxmonthandyear) & "#)"

when i should have had this line:

strWhere = "([monthandyear] = " & "#" & (Me.tboxmonthandyear) & "#)"

i didn't realize that [date] referred to a field NAMED date, so much as it
referred to the date field, because it was formatted that way. it didn't
jump out at me that it was wrong because it didn't look out of place. ah,
well. thanks for your time.
ka******@comcast.net wrote:
tboxmonthandyear is just the month and the year. format is mmm-yyyy. if i
type in 10/2005 in this field it will automatically change it to oct-2005.
this is as desired. the data type of the field is date/time.

the debug.print line came up with this:

([Date] = #10/1/2005#)

now, when i build a query from tblsoldunits in design view, using 10-01-05 as
a criteria, it WILL filter the rest of the records out. the sql looks like
this:

SELECT tblsoldunits.salesperson, tblsoldunits.monthandyear, tblsoldunits.
department, tblsoldunits.units
FROM tblsoldunits
WHERE (((tblsoldunits.monthandyear)=#10/1/2005#));

(btw... i want to be clear and say that the actual name of this table is
tblsoldunits. if i refer to it as tblmonthlyunits it's because it has
changed over the last few weeks as a result of being re-done so many times.
this is just my foggy brain trying to cope with the fact that most of my
tables/forms/queries have been renamed recently and i cling to the old ones.)
The textbox for the date is called txtMonthAndYear. Is this a full date or
just the month and year? What value is in the field? What is the data type

[quoted text clipped - 15 lines]

thanks for looking.


--
Message posted via http://www.accessmonster.com
Nov 28 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: John Martin | last post by:
I am making my first attempt at a project using VBA and have hit a problem. I can find nothing to help in any book. My code is generating a message "Runtime error 2001 You canceled the previous...
2
by: Richard Hollenbeck | last post by:
I got this: "Error 2001 You cancelled the previous operation" with this: Private Sub courseCode_GotFocus() Dim myDLookupResults As String myDLookupResults = DLookup("courseID", "courses",...
2
by: John A. | last post by:
I've received this error several times, and have only been able to get around it by deleting the offending form(s) and importing them from backup - Here's the sequence: 1. I'm editing a form or...
7
by: Neekos | last post by:
Some of this may look familar to some of you, as part of it was posted previously. As i got farther along, i realized i was missing part of it and had to go back and redesign. The code is not fully...
1
by: paulw4 | last post by:
I have the code below to run a query, that is created from a "fill in the blanks" form. I am now getting the error "You cancelled the previous operation" Earlier when I got this I closed the...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.