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
Solved

Pass a parameter in VBA based on external variable value

Posted on 2007-03-21
5
478 Views
Last Modified: 2013-11-25
I have a docmd in VBA that is an append query, but I need to check an external datapoint and depending on that datapoint, the append query should alter the text that is appended to the table.  Am I back to not getting the quotes correct or should the strType be in another format?

If Forms!frmImportMenuFSC.cboForecast = "Budget" Then
    strType = "BUDFSCHSN"
ElseIf Forms!frmImportMenuFSC.cboForecast = "R1" Then
    strType = "R1FSCHSN"
ElseIf Forms!frmImportMenuFSC.cboForecast = "R2" Then
    strType = "R2FSCHSN"
End If


strAppendData = "INSERT INTO tblFSCDetail ( SAP, WorksheetID, ForecastYear, Jan, " & _
    "Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, [Dec] ) " & _
    "SELECT tblTempRetail.SAP," & " ' strType ' " & " AS WorksheetID, " & _
    "FORMS!frmImportMenuFSC.txtForecastYear AS ForecastYear, " & _
    "tblTempRetail.Jan, tblTempRetail.Feb, tblTempRetail.Mar, " & _
    "tblTempRetail.Apr , tblTempRetail.May, tblTempRetail.Jun, " & _
    "tblTempRetail.Jul, tblTempRetail.Aug, tblTempRetail.Sep, " & _
    "tblTempRetail.Oct, tblTempRetail.Nov, tblTempRetail.Dec " & _
    "FROM tblTempRetail "
0
Comment
Question by:ssmith94015
5 Comments
 
LVL 7

Accepted Solution

by:
UniqueData earned 500 total points
ID: 18767316
Instead of:
 "SELECT tblTempRetail.SAP," & " ' strType ' " & " AS WorksheetID, " & _

Try:
 "SELECT tblTempRetail.SAP, '" &  strType   & "' AS WorksheetID, " & _

Michael
0
 
LVL 7

Expert Comment

by:Imoutwest
ID: 18767325
For strType as a string:
>& " ' strType ' " &
should be & "'" & strType & "'" & 

0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 18767351
try this

SELECT tblTempRetail.SAP," & strType & " AS WorksheetID, " &
0
 

Author Comment

by:ssmith94015
ID: 18767370
UniqueData, I do not know what you did because I thought I had tried a version of what wrote, but it did not work I just copied your and it works perfectly.  I think I am getting really tired, I had a nap a few days ago.....  Thank you both.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 18767376
nevermind my post, thought you are passing a name of field.....
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

839 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