If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Formula When Exported From Access Doesn't Work

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-06-09, 11:36
EdAROC EdAROC is offline
Registered User
 
Join Date: Jun 2009
Location: Rochester NY
Posts: 11
Formula When Exported From Access Doesn't Work

We're developing a utility which exports from a query in an Access database into Excel, using the DoCmd.TransferSpreadsheet.

The query value is:
=if(d2<>(f2+h2+j2+l2),"*","")

The formula displays in the cell, as though it's interpreted as being text. If it were preceded by an apostrophe (') I would understand.

If I edit the contents of the cell - merely adding a space at the end and removing the space - then exit the cell, the formula is treated as a formula and the cell displays either the asterisk (*) or nothing, as it should.

Does anyone have suggestions to correct this so that the formula is treated as a formula without having to touch it?
Reply With Quote
  #2 (permalink)  
Old 07-06-09, 12:38
shades shades is offline
Registered User
 
Join Date: Oct 2003
Posts: 1,091
Howdy. In Excel VBA, you could multiply the cell value by 1 which will ensure that it will become a number.
__________________
old, slow, and confused
but at least I'm inconsistent!

Rich
(retired Excel 2003 user, 3/28/2008)

How to ask a question on forums

Last edited by shades; 07-06-09 at 12:42.
Reply With Quote
  #3 (permalink)  
Old 07-06-09, 14:14
Ax238 Ax238 is offline
Registered User
 
Join Date: May 2009
Posts: 257
To get the formula to stick with this method, you'd have to open the spreadsheet and use a macro to set the formula to the value of the cell (c), i.e.
Code:
c.Formula = c.Value
That would need to be performed over all cells with formulas. Otherwise you can use a recordset and build the spreadsheet that way, would be more logic, but would give you more control. I don't see another way at this point.

Regards,

Ax
Reply With Quote
  #4 (permalink)  
Old 07-06-09, 16:49
EdAROC EdAROC is offline
Registered User
 
Join Date: Jun 2009
Location: Rochester NY
Posts: 11
I wasn't sure how to code "In Excel VBA, you could multiply the cell value by 1 which will ensure that it will become a number." (I'm too much a newbie). Was going to ask you how, but, between my posting and now I found out about the .HasFormula and then .Formula properties.

Here's the solution I came up with. The code follows the DoCmd.TransferSpreadsheet code:
- - - - - - -

'Set E Column Formula Property To The Formula
For i = 2 To iLastRow
strRow = Format(iLastRow, "0")
strRange = "E" & strRow
strTemp = "=If(D" & strRow & "<>(F" & strRow & "+H" & strRow & "+J" _
& strRow & "+L" & strRow & "),""*"","""")"
xlWSh.Range(strRange).Formula = strTemp
Next i
- - - - - - -

Rich - BTW: Would you please expand on your suggestion? Where do I place the code? What does the code look like? I'm sure this technique will come in handy some day, no sense passing up an opportunity to learn it now.
Reply With Quote
  #5 (permalink)  
Old 07-06-09, 16:51
EdAROC EdAROC is offline
Registered User
 
Join Date: Jun 2009
Location: Rochester NY
Posts: 11
LOL - While I was busy getting my code working it looks like Ax238 was on the same trail that I was discovering. Thanks.
Reply With Quote
  #6 (permalink)  
Old 07-07-09, 09:08
Ax238 Ax238 is offline
Registered User
 
Join Date: May 2009
Posts: 257
Glad you were able to get it working!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On