SQL Statement Requesting Data in a Certain Format from a MSAccess .mdb into a VB Application

Posted on 2003-03-08
Medium Priority
Last Modified: 2010-05-01
I am using VB6.0 with WIN2000 and a MSAccess .mdb as a container for the data.  I normally use the following statement in a SQL statement to request a date in a "mm/dd/yy" format from the SQL Server:

select convert(varchar(8), DatePurchased, 1) as DatePurchased from tbl_customers

The above code works fine when requesting information from the server.  But when I use this code to request information from a MSAccess .mdb, I get error that "convert" is an undefined function.

Is there a way to order dates in a certain format (or style) from the MS Access .mdb?

The Firebird  
Question by:BirdsOfFire1
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

Expert Comment

ID: 8096088
Hi BirdsOfFire1,

yes, there is: You can use the format function to convert dates from an Access Database. This function needs the date and a format string. I don't remember the format string right now, so if you can't figure it out, just tell me...

Hope that helps

LVL 18

Accepted Solution

Sethi earned 1000 total points
ID: 8096094
That's correct. Convert is a function that is used with SQL Server. With Access and VB you will have to use Format function.

One very important thing to remember about Access is that you will always have to query and insert dates in mm-dd-yyyy format becuase Access doesn't follow the Control Panel> Regional Settings rules.

And unlike SQL Server we have to put a string with "#" Hash symobol to tell Access that it is a date.

This is how you will use the Insert statement. In this example we are inserting the DOB of a child:
strDateOfBirth = "#" & Format(txtDateOfBirth, "mm-dd-yyyy") & "#"

strSQL="Insert into tblChild (DOB) Values(" & strDateOfBirth & ")"

LVL 18

Expert Comment

ID: 8096102
Similarly when you use the SQL query, in your VB code use the following statement:

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!


Expert Comment

ID: 8096143
that's exactly what I wanted to point out ;-)) Thanks, Sethi :-)
LVL 18

Expert Comment

ID: 8096321
LVL 13

Expert Comment

ID: 8097242
Sethi i think that # can also be omitted!
LVL 18

Expert Comment

ID: 8097436
Nope. Access will give you error.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month12 days, 5 hours left to enroll

752 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