?
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
?
201 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
[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
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

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