My Assistant
![]() ![]() |
|
|
Apr 8 2012, 02:08 PM
Post
#1
|
|
|
UtterAccess Ruler Posts: 1,291 From: Kampala,Uganda The Pearl of Africa |
Hello UA
I have an SQL string with a calculated field. I export the results to Excel. i want to format the calculated value. Here is the code.(part of it) CODE Private Sub cmdBalance_Click() Dim db As DAO.Database Dim qdf As DAO.QueryDef Dim strSQL As String On Error GoTo myErr Select Case Me.Frame4.Value Case Is = 1 strSQL = "SELECT qryQuarterlyRF.Description, qryQuarterlyRF.ActivityName," & _ " qryQuarterlyRF.CategoryName, qryQuarterlyRF.Aproved_Amount, qryQuarterlyRF.Q1, " & _ "Nz[qryQuarterlyRF]![Aproved_Amount],0)-Nz([qryQuarterlyRF]![Q1],0) AS Balance" & _ " From qryQuarterlyRF " & _ " WHERE (((qryQuarterlyRF.Quarter)=1));" Set db = CurrentDb() Set qdf = db.CreateQueryDef("qryQBalance", strSQL) DoCmd.OutputTo acOutputQuery, "qryQBalance", "ExcelWorkbook(*.xlsx)", "", True, "", 0, acExportQualityPrint myExit: On Error Resume Next DoCmd.DeleteObject acQuery, "qryQBalance" Set qdf = Nothing Set db = Nothing myErr: MsgBox " Error" & Err.Description Resume myExit End Sub The part i want formatted( Currency formatting) in SQL is this one CODE "Nz[qryQuarterlyRF]![Aproved_Amount],0)-Nz([qryQuarterlyRF]![Q1],0) AS Balance" & _ Ronald |
|
|
|
Apr 8 2012, 02:20 PM
Post
#2
|
|
|
Access Wiki and Forums Moderator Posts: 47,962 From: SoCal, USA |
Hi Ronald,
What version of Access are you using? Please remember to select the version number when posting questions in case it becomes relevant to the discussion. Have you tried something like? Format(Nz(qryQuarterlyRF.Approved_Amount,0)-Nz(qryQuarterlyRF.Q1,0), "Currency") As Balance Just my 2 cents... (IMG:style_emoticons/default/2cents.gif) |
|
|
|
Apr 8 2012, 02:32 PM
Post
#3
|
|
|
UtterAccess Ruler Posts: 1,291 From: Kampala,Uganda The Pearl of Africa |
Hi Ronald, What version of Access are you using? Please remember to select the version number when posting questions in case it becomes relevant to the discussion. Have you tried something like? Format(Nz(qryQuarterlyRF.Approved_Amount,0)-Nz(qryQuarterlyRF.Q1,0), "Currency") As Balance Just my 2 cents... (IMG:style_emoticons/default/2cents.gif) Hello Dbguy. I am using Access 2007. Tried your suggestion but it is not compiling. can an SQL string work with out the quotes(")? Ronald |
|
|
|
Apr 8 2012, 02:33 PM
Post
#4
|
|
|
Access Wiki and Forums Moderator Posts: 47,962 From: SoCal, USA |
Try using single quotes instead (forgot that you're using this in VBA).
Just my 2 cents... (IMG:style_emoticons/default/2cents.gif) |
|
|
|
Apr 8 2012, 02:40 PM
Post
#5
|
|
|
UtterAccess Ruler Posts: 1,291 From: Kampala,Uganda The Pearl of Africa |
Try using single quotes instead (forgot that you're using this in VBA). Just my 2 cents... (IMG:style_emoticons/default/2cents.gif) Hello Dbguy Even single quotes dont compile. Ronald |
|
|
|
Apr 8 2012, 02:48 PM
Post
#6
|
|
|
UtterAccess Ruler Posts: 1,816 From: SoCal, USA |
QUOTE strSQL = "SELECT qryQuarterlyRF.Description, qryQuarterlyRF.ActivityName," & _ " qryQuarterlyRF.CategoryName, qryQuarterlyRF.Aproved_Amount, qryQuarterlyRF.Q1, " & _ "Nz[qryQuarterlyRF]![Aproved_Amount],0)-Nz([qryQuarterlyRF]![Q1],0) AS Balance" & _ " From qryQuarterlyRF " & _ " WHERE (((qryQuarterlyRF.Quarter)=1));" PMFJI, guys. Ronald, above is the SQL statement you originally posted. i noticed that the bolded NZ function is incorrect - it's missing the opening perens. if you didn't fix that already, you'll want to do so or the query won't run even after the code compiles. hth tina |
|
|
|
Apr 8 2012, 02:59 PM
Post
#7
|
|
|
UtterAccess Ruler Posts: 1,291 From: Kampala,Uganda The Pearl of Africa |
PMFJI, guys. Ronald, above is the SQL statement you originally posted. i noticed that the bolded NZ function is incorrect - it's missing the opening perens. if you didn't fix that already, you'll want to do so or the query won't run even after the code compiles. hth tina Thank you Tina t This one has worked CODE strSQL = "SELECT qryQuarterlyRF.Description, qryQuarterlyRF.ActivityName," & _ " qryQuarterlyRF.CategoryName, qryQuarterlyRF.Aproved_Amount, qryQuarterlyRF.Q1, " & _ " Format(Nz([qryQuarterlyRF]![Aproved_Amount],0)-Nz([qryQuarterlyRF]![Q1],0),'Currency') AS Balance" & _ " From qryQuarterlyRF " & _ " WHERE (((qryQuarterlyRF.Quarter)=1));" Ronald |
|
|
|
Apr 8 2012, 03:51 PM
Post
#8
|
|
|
Access Wiki and Forums Moderator Posts: 47,962 From: SoCal, USA |
Hi Ronald,
Glad to hear you got it to work but I don't understand. It looks like you used the single quote suggestion I made earlier; but back then, you said it didn't work. (IMG:style_emoticons/default/iconfused.gif) |
|
|
|
Apr 9 2012, 12:50 AM
Post
#9
|
|
|
UtterAccess Ruler Posts: 1,291 From: Kampala,Uganda The Pearl of Africa |
Hi Ronald, Glad to hear you got it to work but I don't understand. It looks like you used the single quote suggestion I made earlier; but back then, you said it didn't work. (IMG:style_emoticons/default/iconfused.gif) Hello Dbguy I think it was not working because i did not include the opening quotes...i was using CODE Format(Nz([qryQuarterlyRF]![Aproved_Amount],0)-Nz([qryQuarterlyRF]![Q1],0),'Currency') AS Balance & _ Then tried CODE " Format(Nz([qryQuarterlyRF]![Aproved_Amount],0)-Nz([qryQuarterlyRF]![Q1],0),'Currency') AS Balance" & _ which worked Of course got it working because of your advice Thank you so much Ronald |
|
|
|
Apr 9 2012, 10:57 AM
Post
#10
|
|
|
Access Wiki and Forums Moderator Posts: 47,962 From: SoCal, USA |
|
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 22nd May 2013 - 06:41 AM |