Link to home
Start Free TrialLog in
Avatar of maxwell2323
maxwell2323

asked on

OpenForm with date range criteria VBA issue - Access 2003 with SQL back end

I have a form (Form A) where a user can enter and or select search criteria (including from and to dates) and hit a Search button to bring up another form (Form B) displaying results. The record source of Form B is a specific table. This is an Access application where the Access tables are linked to their counterparts in a SQL 2000 database. My issues is this: when a date range is the criteria, when I hit Search, I get the runtime error 2501 Open form action was canceled error message.

What is interesting is this: in the immediate window I can copy what is displayed by the Debug Print, and I can paste this into SQL Enterprise Manager SQL pane (after locating the table involved and displaying all rows). And when I run the query, I actually get results. What are your thoughts? Do you see issues with the code snippet? The code snippet is in the click event of the Search button of Form A.

stLinkCriteria = "[TransactionDate] >= '" & Me![BeginDate].Value & "' AND [TransactionDate] <= '" & Me![EndDate].Value & "'"    
stDocName = "PreEntry"
    Debug.Print stLinkCriteria
    DoCmd.OpenForm stDocName, , , stLinkCriteria

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of maxwell2323
maxwell2323

ASKER

That totally solved the issue. Thanks !!