Solved

Insert combo box text into query string

Posted on 2007-03-26
6
165 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
  • 4
  • 2
6 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:janderscu
Comment Utility
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
Comment Utility
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
Comment Utility
>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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now