Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2003-03-08
7
Medium Priority
?
202 Views
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?


Thanks
The Firebird  
0
Comment
Question by:BirdsOfFire1
  • 4
  • 2
7 Comments
 
LVL 3

Expert Comment

by:owitte
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
Oliver

0
 
LVL 18

Accepted Solution

by:
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 & ")"

0
 
LVL 18

Expert Comment

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

txtdateofbirth=Format(rsgetdata("DOB"),"dd-mm-yyyy")
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!

 
LVL 3

Expert Comment

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

Expert Comment

by:Sethi
ID: 8096321
;-))
0
 
LVL 13

Expert Comment

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

Expert Comment

by:Sethi
ID: 8097436
Nope. Access will give you error.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Suggested Courses

569 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