Runtime error 2001

M

m44pablo

Have 2 command buttons that open 1 form.
First button opens fine with the specied recordsource but
the other one comes up with
"Runtime error 2001
You canceled the previous operation."


code as follows:
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmOrgSurveyModule"

stLinkCriteria = "[Org_seqno]=" & "'" & Me![Org_seqno]
& "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

If IsFormLoaded("frmOrganization") = True Then
Forms!frmOrgsurveymodule.txtorg_seqno = Me.Org_seqno
Forms!frmOrgsurveymodule.Label1.Caption = "PEP
CONSULTANT IMPLEMENTATION SURVEY"
Forms!frmOrgsurveymodule.lblSurveyMonth.Visible =
True
Forms!frmOrgsurveymodule.frmSurveyMonth.Enabled =
True
Forms!frmOrgsurveymodule.frmSurveyMonth.Locked =
False
Forms!frmOrgsurveymodule.frmSurveyMonth.Visible =
True
Forms!frmOrgsurveymodule.RecordSource = "select *
from tblorgsurveymodule where survey_mo in (3,6,9,12)"




End If

if I try to debug it - just highlight the recordsource.
Can't figure this out!!!
I need to change the recordsource if the other button is
pressed.
Help.
Thanks.
 
A

Allen Browne

Error 2001 generally means that the SQL string is incorrect, or that there
is a record in the form that cannot be saved at present, so the RecordSource
can't be changed.

If you open tblOrgSurveyModule in design view, what is the Data Type of the
Survey_Mo field?

If Text (not Number), you need quotes around the arguments, i.e.:
Forms!frmOrgsurveymodule.RecordSource = _
"select * from tblorgsurveymodule where survey_mo in ('3','6','9','12')"

If that still does not work, create a new query, and paste in the contents
of your string into SQL View (View menu when in query design) to see what's
wrong.

The other thing is to test the Dirty property of the form before assigning
the RecordSource.
 
L

Luke

Thank you for your advise.
It now works.
-----Original Message-----
Error 2001 generally means that the SQL string is incorrect, or that there
is a record in the form that cannot be saved at present, so the RecordSource
can't be changed.

If you open tblOrgSurveyModule in design view, what is the Data Type of the
Survey_Mo field?

If Text (not Number), you need quotes around the arguments, i.e.:
Forms!frmOrgsurveymodule.RecordSource = _
"select * from tblorgsurveymodule where survey_mo in ('3','6','9','12')"

If that still does not work, create a new query, and paste in the contents
of your string into SQL View (View menu when in query design) to see what's
wrong.

The other thing is to test the Dirty property of the form before assigning
the RecordSource.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Have 2 command buttons that open 1 form.
First button opens fine with the specied recordsource but
the other one comes up with
"Runtime error 2001
You canceled the previous operation."


code as follows:
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmOrgSurveyModule"

stLinkCriteria = "[Org_seqno]=" & "'" & Me! [Org_seqno]
& "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

If IsFormLoaded("frmOrganization") = True Then
Forms!frmOrgsurveymodule.txtorg_seqno = Me.Org_seqno
Forms!frmOrgsurveymodule.Label1.Caption = "PEP
CONSULTANT IMPLEMENTATION SURVEY"
Forms!frmOrgsurveymodule.lblSurveyMonth.Visible =
True
Forms!frmOrgsurveymodule.frmSurveyMonth.Enabled =
True
Forms!frmOrgsurveymodule.frmSurveyMonth.Locked =
False
Forms!frmOrgsurveymodule.frmSurveyMonth.Visible =
True
Forms!frmOrgsurveymodule.RecordSource = "select *
from tblorgsurveymodule where survey_mo in (3,6,9,12)"




End If

if I try to debug it - just highlight the recordsource.
Can't figure this out!!!
I need to change the recordsource if the other button is
pressed.
Help.
Thanks.


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top