Solved

Insert combo box text into query string

Posted on 2007-03-26
6
175 Views
Last Modified: 2013-12-25
I have the following query string that I am using to open a recordset in a VBA module in Access.  I want to substitute the hard-coded date with the text from a combo box that I use as a calendar date picker.  

    Set rst2 = CurrentDb.OpenRecordset("SELECT PATIENTS.LAST, PATIENTS.FIRST, PATIENTS.HOSP, [History Table].Staff_MarkerPlacement,[History Table].[Study Date], [History Table].Process, [History Table].ReadyforInterps, [History Table].Interp, [History Table].Coded, [History Table].Contact, [History Table].[Schedule Tx] FROM PATIENTS INNER JOIN [History Table]ON PATIENTS.HOSP = [History Table].[MR #] WHERE ((([History Table].[Study Date]) >= #1/1/05#))ORDER BY [History Table].[Study Date], PATIENTS.HOSP, [History Table].[Study Date]")

When I substitute in    Forms![Database Total Form]![cboStartDate].[Text]  it doesn't work.  I can't get it to show me an actual error message (that is another issue I am having), but I know it is not working because the code does not execute and update my form

Any help?  Thanks.
0
Comment
Question by:janderscu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 250 total points
ID: 18794843
Try this:

Set rst2 = CurrentDb.OpenRecordset("SELECT PATIENTS.LAST, PATIENTS.FIRST, PATIENTS.HOSP, [History Table].Staff_MarkerPlacement,[History Table].[Study Date], [History Table].Process, [History Table].ReadyforInterps, [History Table].Interp, [History Table].Coded, [History Table].Contact, [History Table].[Schedule Tx] FROM PATIENTS INNER JOIN [History Table]ON PATIENTS.HOSP = [History Table].[MR #] WHERE ((([History Table].[Study Date]) >= #" & Forms![Database Total Form]![cboStartDate] & "#))ORDER BY [History Table].[Study Date], PATIENTS.HOSP, [History Table].[Study Date]")
0
 

Author Comment

by:janderscu
ID: 18795444
That works great!  Thanks.

By the way, do you know how to set up VBA in Access so that it will halt execution and give you an error message when there is an error (like when writing a program in regular Visual basic).  Right now all it does is not work, and I often have problems determining what the problem is.  Ideas?
0
 
LVL 61

Expert Comment

by:mbizup
ID: 18795603
Hi,

I'm not quite clear on what you are asking.  Are you looking for  VBA error handling for code that fails?
>Right now all it does is not work
In what respect?
The SQL Statement? or the VBA itself?  

Thanks.
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 

Author Comment

by:janderscu
ID: 18795651
Sorry for not being clear.  Hopefully I can explain it better ..

Normally, when I write a program in Visual Basic, if there is an error, it will halt execution and pop up a window saying there is an error with a description, and then you can hit the Debug button and it will take you to the point in the code where the error occurs.

But when I am writing a module in VBA, that does not happen.  If the VBA code has a problem, I get no window that pops up and no error messages appear.  So nothing happens and I have no idea where there is a problem.  It just seems like the code encounters an error and jumps out without telling me what the problem is.  

Is there some setting somewhere that enables the error message\debug feature in VBA?

0
 
LVL 61

Expert Comment

by:mbizup
ID: 18795844
In the VBA editor, Tools -> Options -> General
Your error handling should be selected as "break on unhandled errors", which will cause the code to fail on errors you havent explicitly written code to handle (or used something like "On Error Resume Next" for)  if you run your application through design view.  If errors are causing your run-time application to "hang" or otherwise misbehave, add error handling:

On Error Goto EH
      ...
      ...
       YourCode
      ...
      Exit Function '(Or Sub)
EH:
   Msgbox "Error " & err.num & ": " & err.description
end function
0
 
LVL 61

Expert Comment

by:mbizup
ID: 18795853
>If errors are causing your run-time application to "hang" or otherwise misbehave, add error handling:
I didn't phrase that very well... You really should have something like that in ALL of your procedures.
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question