Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 30th, 2008, 06:18 AM
Authorized User
 
Join Date: Oct 2007
Posts: 46
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via MSN to debbiecoates
Default vb Format equivalent in SQL

I have a table in SQL which looks like this

RequestedChangeID ProjectID RequestedChangeNumber
140 10012 1
141 10012 2
142 10012 3
143 10012 4
144 10012 5


in vb I can crate a select query to display the data in a recordset like this

SELECT PROJECTREQUESTEDCHANGE.RequestedChangeID, [ProjectID] & "-RC" & Format([RequestedChangeNumber],"000") AS ChangeNumber, PROJECTREQUESTEDCHANGE.MediaDate AS [Date]
FROM PROJECTREQUESTEDCHANGE;

which gives me

RequestedChangeID ChangeNumber Date
140 10012-RC001 30/09/2008
141 10012-RC002 30/09/2008
142 10012-RC003 30/09/2008
143 10012-RC004 30/09/2008
144 10012-RC005 30/09/2008

but the format funtion doesn't work in SQl, so I am not sure how to do it, can anyone help please


 
Old September 30th, 2008, 07:01 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default


You wrote:
> I have a table in SQL which looks like this

Since this is an Access forum, I *hope* you mean you have a table in Access that looks like this. I only am checking because SO many people say "in SQL" when they mean "in SQL Server", and of course this forum is not for SQL Server.

ANYWAY...

Assuming you *DO* mean "in Access", then the answer is easy: 100% the same.

You said "in vb I can crate [sic] a select query ..." But you are wrong. That is *ACTUALLY* a SELECT query in SQL. It just happens to be the dialect of SQL that Access understands. So you must have been using Access when you were working with VB.

Now, if you really *DID* mean "SQL Server" and you asked in the wrong forum, then I should tell you to change forums. But it's not worth it. The answer is dead easy.
     SELECT ProjectID + '-RC' + RIGHT('000' + RequestedChangeNumber, 3 ) AS ChangeNumber

Incidentally, that solution works in Access, as well. Though you might then want to change the + signs to & operators.
 
Old November 5th, 2008, 03:22 PM
pjm pjm is offline
Authorized User
 
Join Date: Jul 2006
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have found that the FORMAT function does work as you have it above within an Access query.


      -Phil-





Similar Threads
Thread Thread Starter Forum Replies Last Post
VB equivalent of this C# code yukijocelyn ASP.NET 2.0 Basics 2 October 1st, 2007 10:22 PM
What is the Equivalent Syntax in VB.NET r_taduri VB.NET 2002/2003 Basics 1 June 2nd, 2006 12:49 PM
What is the VB equivalent to the Inkey$ command ? RichardCyberPunk Beginning VB 6 1 December 8th, 2005 01:42 PM
What is C# Component equivalent to in VB.NET bekim C# 3 July 1st, 2004 03:24 PM
VB6! what is the VB.Net equivalent Louisa VB.NET 2002/2003 Basics 2 January 15th, 2004 12:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.