Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 17th, 2006, 03:04 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 114
Thanks: 0
Thanked 0 Times in 0 Posts
Default The OpenForm action was canceled

You used a method of the DoCmd object to carry out an action in Visual Basic, but then clicked Cancel in a dialog box.

stLinkCriteria = "[Employee_Courses].[COURSE_DATE]='" & Me.TrainingDate.Value & "' AND [LKPTrainingType].[TrainingTypeDesc]='" & Me.txtTrainingType & "' AND [SiteCode]='" & Forms!frmProperty!SiteCodeCombo & "' AND [BlockNo]='" & Forms!frmProperty!BlockCodeCombo & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

The value of stLinkCriteria is as follows:

[Employee_Courses].[COURSE_DATE]='22/03/2006' AND [LKPTrainingType].[TrainingTypeDesc]='Fire Induction' AND [SiteCode]='21800' AND [BlockNo]='01'

I have tried a variation (below) which works, but cannot see what's going on with the date.

[LKPTrainingType].[TrainingTypeDesc]='Fire Induction' AND [SiteCode]='21800' AND [BlockNo]='01'

Any help appreciated...

Regards,

Sean Anderson
__________________
Regards,

Sean Anderson
 
Old October 17th, 2006, 03:12 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 114
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Additionally, I have tried with no success, to reformat the date (as below) and have also tried each with '#' surrounding the date.

dd/mm/yyyy
mm/dd/yyyy
yyyy-mm-dd

Regards,

Sean Anderson
 
Old October 17th, 2006, 06:47 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 114
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Terribly frustrating that this was something so glaringly obvious.

Changing the date format so that the line now reads as follows did the trick.

stLinkCriteria = "[Employee_Courses].[COURSE_DATE]=#" & Format(Me.TrainingDate.Value, "mm/dd/yyyy") & "# AND [LKPTrainingType].[TrainingTypeDesc]='" & Me.txtTrainingType & "' AND [SiteCode]='" & Forms!frmProperty!SiteCodeCombo & "' AND [BlockNo]='" & Forms!frmProperty!BlockCodeCombo & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Resulting in stLinkCriteria being equal to the following.

[Employee_Courses].[COURSE_DATE]=#03/22/2006# AND [LKPTrainingType].[TrainingTypeDesc]='Fire Induction' AND [SiteCode]='21800' AND [BlockNo]='01'

Regards,

Sean Anderson
 
Old October 18th, 2006, 12:34 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Alternatively, you can place the criteria for the date directly in the query designer. In the first Criteria cell under the COURSE_DATE column, put:

[Forms]![frmMyFormName].[TrainingDate]

In the TrainingTypeDesc column put:

[Forms]![frmMyFormName].[txtTraningType]

etc.

This will allow you to just have this code on your button:

'----------------------
Dim stDocName As String
stDocName = "rptMyReportName"
DoCmd.OpenForm stDocName
'----------------------

The downside is that the query can only be used with that report when the form is opened. Ideally you would have some sort of check on the form to make sure all the values had been selected.

HTH




mmcdonal





Similar Threads
Thread Thread Starter Forum Replies Last Post
Request action on change and get no action. Help crussell Ajax 0 September 12th, 2007 11:11 AM
"The OpenForm command was canceled" Bob Pierce Access 2 April 24th, 2007 05:07 AM
Error 2001 You canceled the previous operation RayL Access VBA 3 December 8th, 2006 03:00 PM
"you canceled the previous operation" error Totenkopf Access VBA 2 June 14th, 2006 02:48 PM
you canceled the previous operation lizhaskin Access 1 July 19th, 2005 12:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.