Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Insert combo box text into query string

Posted on 2007-03-26
6
Medium Priority
?
180 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 1000 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

604 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