beginner vba sql query question

sokoye1

New member
Local time
Today, 06:28
Joined
Nov 19, 2013
Messages
6
I'm trying to create a VBA application that would allow for a given date (datetimepicker) to display in a datagridview a list of records (uploaded from a database) that occur before and after the given date(2 radiobuttons). What would be the best way to go about creating this application?

If I were to use a query, I would need to go to the TableAdapter and add query. The query should look like this, correct?

Select (Info needed) From dbo.Records

Next, I would need to put the Where statement, but I'm not exactly sure what to put here.


Any help would be greatly appreciated.
 
Have you tried using the query builder? Copy the SQL then adjust the where clause with variables in code.

Here's an example of one of my WHERE clauses built in VBA:
Code:
" WHERE (((Incidents.[Occurrence Date]) Between " & datBegin & " And " & datEnd & "))" _
 
Do not confuse VBA with VB.net - two entirely different things. I don't quite remember what Access dates look like from within VB.net - search for that on a .net forum.
 
The example I provided is from a VBA project / Access 2007. As long as the variable type is declared as a Date, you should be fine. I have found that using a string like 1/1/2001 must be wrapped like this #1/1/2001# to be interpreted as a date.

If you are in fact using vb.net and not VBA, then this may be of help:
http://www.dreamincode.net/forums/topic/148532-using-datagridview-with-access/
 

Users who are viewing this thread

Back
Top Bottom