Parameter inside identifier












0















I'm trying to write a add query that will change depending on the parameter. I have several queries:



LastK1StatDate

LastK2StatDate

.

.

LastK15StatDate

LastK16StatDate



My criteria should change depending on the value entered for the parameter "qryKioskNum" when the query is run.



Currently my criteria is this:



>Max("[LastK" & [qryKioskNum] & "StatDate]![K" & [qryKioskNum] & "LastDate]")


qryKioskNum is type Short Text



It keeps giving me the error "The expression is typed incorrectly, or is too complex to be evaluated."



Here is the complete SQL statement for this query:



PARAMETERS qryKioskNum Short;  
INSERT INTO K1DispRejStat ( K1StatDate, K1BillCount1, K1BillCount2,
K1BillCount3, K1BillCount4, K1BillCount5, K1BillCount6, K1BillRej1,
K1BillRej2, K1BillRej3, K1BillRej4, K1BillRej5, K1BillRej6 )
SELECT DateValue([responseFrames]![dispDateTime]) AS [Date],
Sum(responseFrames.billCount1) AS SumOfbillCount1,
Sum(responseFrames.billCount2) AS SumOfbillCount2,
Sum(responseFrames.billCount3) AS SumOfbillCount3,
Sum(responseFrames.billCount4) AS SumOfbillCount4,
Sum(responseFrames.billCount5) AS SumOfbillCount5,
Sum(responseFrames.billCount6) AS SumOfbillCount6,
Sum(responseFrames.BillRej1) AS SumOfBillRej1, Sum(responseFrames.BillRej2)
AS SumOfBillRej2, Sum(responseFrames.BillRej3) AS SumOfBillRej3,
Sum(responseFrames.BillRej4) AS SumOfBillRej4, Sum(responseFrames.billRej5)
AS SumOfbillRej5, Sum(responseFrames.billRej6) AS SumOfbillRej6
FROM responseFrames, LastK1StatDate
WHERE (((responseFrames.kioskID)="K1"))
GROUP BY DateValue([responseFrames]![dispDateTime])
HAVING (((DateValue([responseFrames]![dispDateTime]))>Max("[LastK" &
[qryKioskNum] & "StatDate]![K1LastDate]")))
ORDER BY DateValue([responseFrames]![dispDateTime]);


currently everything is set to "K1" but I would like all reference to K1 to be dynamic



I think it is just a syntax issue but can't find how exactly this should be typed out.



Any help is great. Thanks!



*edited for clarity










share|improve this question

























  • add tempTxt = "[LastK" & [qryKioskNum] & "StatDate]![K1LastDate]" and then msgbox(tempTxt), and then Max(tempTxt). Tell us what you see. What do you expect to get? How does KDispRejStat fit into this? Or is it just spurious information?

    – donPablo
    Jan 2 at 17:25











  • Where am I adding all of this? Should this all go in the criteria?

    – jawohl
    Jan 2 at 17:34













  • Are you trying to do this in query object or build SQL in VBA? Post the entire SQL. Where is the value of qryKioskNum coming from? You have 16 query objects and you want to dynamically select which is referenced in another query object? I don't think that is possible.

    – June7
    Jan 2 at 17:55











  • I added quite a bit to clarify my exact question. I also included the SQL statement that you asked for.

    – jawohl
    Jan 2 at 18:24
















0















I'm trying to write a add query that will change depending on the parameter. I have several queries:



LastK1StatDate

LastK2StatDate

.

.

LastK15StatDate

LastK16StatDate



My criteria should change depending on the value entered for the parameter "qryKioskNum" when the query is run.



Currently my criteria is this:



>Max("[LastK" & [qryKioskNum] & "StatDate]![K" & [qryKioskNum] & "LastDate]")


qryKioskNum is type Short Text



It keeps giving me the error "The expression is typed incorrectly, or is too complex to be evaluated."



Here is the complete SQL statement for this query:



PARAMETERS qryKioskNum Short;  
INSERT INTO K1DispRejStat ( K1StatDate, K1BillCount1, K1BillCount2,
K1BillCount3, K1BillCount4, K1BillCount5, K1BillCount6, K1BillRej1,
K1BillRej2, K1BillRej3, K1BillRej4, K1BillRej5, K1BillRej6 )
SELECT DateValue([responseFrames]![dispDateTime]) AS [Date],
Sum(responseFrames.billCount1) AS SumOfbillCount1,
Sum(responseFrames.billCount2) AS SumOfbillCount2,
Sum(responseFrames.billCount3) AS SumOfbillCount3,
Sum(responseFrames.billCount4) AS SumOfbillCount4,
Sum(responseFrames.billCount5) AS SumOfbillCount5,
Sum(responseFrames.billCount6) AS SumOfbillCount6,
Sum(responseFrames.BillRej1) AS SumOfBillRej1, Sum(responseFrames.BillRej2)
AS SumOfBillRej2, Sum(responseFrames.BillRej3) AS SumOfBillRej3,
Sum(responseFrames.BillRej4) AS SumOfBillRej4, Sum(responseFrames.billRej5)
AS SumOfbillRej5, Sum(responseFrames.billRej6) AS SumOfbillRej6
FROM responseFrames, LastK1StatDate
WHERE (((responseFrames.kioskID)="K1"))
GROUP BY DateValue([responseFrames]![dispDateTime])
HAVING (((DateValue([responseFrames]![dispDateTime]))>Max("[LastK" &
[qryKioskNum] & "StatDate]![K1LastDate]")))
ORDER BY DateValue([responseFrames]![dispDateTime]);


currently everything is set to "K1" but I would like all reference to K1 to be dynamic



I think it is just a syntax issue but can't find how exactly this should be typed out.



Any help is great. Thanks!



*edited for clarity










share|improve this question

























  • add tempTxt = "[LastK" & [qryKioskNum] & "StatDate]![K1LastDate]" and then msgbox(tempTxt), and then Max(tempTxt). Tell us what you see. What do you expect to get? How does KDispRejStat fit into this? Or is it just spurious information?

    – donPablo
    Jan 2 at 17:25











  • Where am I adding all of this? Should this all go in the criteria?

    – jawohl
    Jan 2 at 17:34













  • Are you trying to do this in query object or build SQL in VBA? Post the entire SQL. Where is the value of qryKioskNum coming from? You have 16 query objects and you want to dynamically select which is referenced in another query object? I don't think that is possible.

    – June7
    Jan 2 at 17:55











  • I added quite a bit to clarify my exact question. I also included the SQL statement that you asked for.

    – jawohl
    Jan 2 at 18:24














0












0








0








I'm trying to write a add query that will change depending on the parameter. I have several queries:



LastK1StatDate

LastK2StatDate

.

.

LastK15StatDate

LastK16StatDate



My criteria should change depending on the value entered for the parameter "qryKioskNum" when the query is run.



Currently my criteria is this:



>Max("[LastK" & [qryKioskNum] & "StatDate]![K" & [qryKioskNum] & "LastDate]")


qryKioskNum is type Short Text



It keeps giving me the error "The expression is typed incorrectly, or is too complex to be evaluated."



Here is the complete SQL statement for this query:



PARAMETERS qryKioskNum Short;  
INSERT INTO K1DispRejStat ( K1StatDate, K1BillCount1, K1BillCount2,
K1BillCount3, K1BillCount4, K1BillCount5, K1BillCount6, K1BillRej1,
K1BillRej2, K1BillRej3, K1BillRej4, K1BillRej5, K1BillRej6 )
SELECT DateValue([responseFrames]![dispDateTime]) AS [Date],
Sum(responseFrames.billCount1) AS SumOfbillCount1,
Sum(responseFrames.billCount2) AS SumOfbillCount2,
Sum(responseFrames.billCount3) AS SumOfbillCount3,
Sum(responseFrames.billCount4) AS SumOfbillCount4,
Sum(responseFrames.billCount5) AS SumOfbillCount5,
Sum(responseFrames.billCount6) AS SumOfbillCount6,
Sum(responseFrames.BillRej1) AS SumOfBillRej1, Sum(responseFrames.BillRej2)
AS SumOfBillRej2, Sum(responseFrames.BillRej3) AS SumOfBillRej3,
Sum(responseFrames.BillRej4) AS SumOfBillRej4, Sum(responseFrames.billRej5)
AS SumOfbillRej5, Sum(responseFrames.billRej6) AS SumOfbillRej6
FROM responseFrames, LastK1StatDate
WHERE (((responseFrames.kioskID)="K1"))
GROUP BY DateValue([responseFrames]![dispDateTime])
HAVING (((DateValue([responseFrames]![dispDateTime]))>Max("[LastK" &
[qryKioskNum] & "StatDate]![K1LastDate]")))
ORDER BY DateValue([responseFrames]![dispDateTime]);


currently everything is set to "K1" but I would like all reference to K1 to be dynamic



I think it is just a syntax issue but can't find how exactly this should be typed out.



Any help is great. Thanks!



*edited for clarity










share|improve this question
















I'm trying to write a add query that will change depending on the parameter. I have several queries:



LastK1StatDate

LastK2StatDate

.

.

LastK15StatDate

LastK16StatDate



My criteria should change depending on the value entered for the parameter "qryKioskNum" when the query is run.



Currently my criteria is this:



>Max("[LastK" & [qryKioskNum] & "StatDate]![K" & [qryKioskNum] & "LastDate]")


qryKioskNum is type Short Text



It keeps giving me the error "The expression is typed incorrectly, or is too complex to be evaluated."



Here is the complete SQL statement for this query:



PARAMETERS qryKioskNum Short;  
INSERT INTO K1DispRejStat ( K1StatDate, K1BillCount1, K1BillCount2,
K1BillCount3, K1BillCount4, K1BillCount5, K1BillCount6, K1BillRej1,
K1BillRej2, K1BillRej3, K1BillRej4, K1BillRej5, K1BillRej6 )
SELECT DateValue([responseFrames]![dispDateTime]) AS [Date],
Sum(responseFrames.billCount1) AS SumOfbillCount1,
Sum(responseFrames.billCount2) AS SumOfbillCount2,
Sum(responseFrames.billCount3) AS SumOfbillCount3,
Sum(responseFrames.billCount4) AS SumOfbillCount4,
Sum(responseFrames.billCount5) AS SumOfbillCount5,
Sum(responseFrames.billCount6) AS SumOfbillCount6,
Sum(responseFrames.BillRej1) AS SumOfBillRej1, Sum(responseFrames.BillRej2)
AS SumOfBillRej2, Sum(responseFrames.BillRej3) AS SumOfBillRej3,
Sum(responseFrames.BillRej4) AS SumOfBillRej4, Sum(responseFrames.billRej5)
AS SumOfbillRej5, Sum(responseFrames.billRej6) AS SumOfbillRej6
FROM responseFrames, LastK1StatDate
WHERE (((responseFrames.kioskID)="K1"))
GROUP BY DateValue([responseFrames]![dispDateTime])
HAVING (((DateValue([responseFrames]![dispDateTime]))>Max("[LastK" &
[qryKioskNum] & "StatDate]![K1LastDate]")))
ORDER BY DateValue([responseFrames]![dispDateTime]);


currently everything is set to "K1" but I would like all reference to K1 to be dynamic



I think it is just a syntax issue but can't find how exactly this should be typed out.



Any help is great. Thanks!



*edited for clarity







ms-access






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 18:21







jawohl

















asked Jan 2 at 17:07









jawohljawohl

52




52













  • add tempTxt = "[LastK" & [qryKioskNum] & "StatDate]![K1LastDate]" and then msgbox(tempTxt), and then Max(tempTxt). Tell us what you see. What do you expect to get? How does KDispRejStat fit into this? Or is it just spurious information?

    – donPablo
    Jan 2 at 17:25











  • Where am I adding all of this? Should this all go in the criteria?

    – jawohl
    Jan 2 at 17:34













  • Are you trying to do this in query object or build SQL in VBA? Post the entire SQL. Where is the value of qryKioskNum coming from? You have 16 query objects and you want to dynamically select which is referenced in another query object? I don't think that is possible.

    – June7
    Jan 2 at 17:55











  • I added quite a bit to clarify my exact question. I also included the SQL statement that you asked for.

    – jawohl
    Jan 2 at 18:24



















  • add tempTxt = "[LastK" & [qryKioskNum] & "StatDate]![K1LastDate]" and then msgbox(tempTxt), and then Max(tempTxt). Tell us what you see. What do you expect to get? How does KDispRejStat fit into this? Or is it just spurious information?

    – donPablo
    Jan 2 at 17:25











  • Where am I adding all of this? Should this all go in the criteria?

    – jawohl
    Jan 2 at 17:34













  • Are you trying to do this in query object or build SQL in VBA? Post the entire SQL. Where is the value of qryKioskNum coming from? You have 16 query objects and you want to dynamically select which is referenced in another query object? I don't think that is possible.

    – June7
    Jan 2 at 17:55











  • I added quite a bit to clarify my exact question. I also included the SQL statement that you asked for.

    – jawohl
    Jan 2 at 18:24

















add tempTxt = "[LastK" & [qryKioskNum] & "StatDate]![K1LastDate]" and then msgbox(tempTxt), and then Max(tempTxt). Tell us what you see. What do you expect to get? How does KDispRejStat fit into this? Or is it just spurious information?

– donPablo
Jan 2 at 17:25





add tempTxt = "[LastK" & [qryKioskNum] & "StatDate]![K1LastDate]" and then msgbox(tempTxt), and then Max(tempTxt). Tell us what you see. What do you expect to get? How does KDispRejStat fit into this? Or is it just spurious information?

– donPablo
Jan 2 at 17:25













Where am I adding all of this? Should this all go in the criteria?

– jawohl
Jan 2 at 17:34







Where am I adding all of this? Should this all go in the criteria?

– jawohl
Jan 2 at 17:34















Are you trying to do this in query object or build SQL in VBA? Post the entire SQL. Where is the value of qryKioskNum coming from? You have 16 query objects and you want to dynamically select which is referenced in another query object? I don't think that is possible.

– June7
Jan 2 at 17:55





Are you trying to do this in query object or build SQL in VBA? Post the entire SQL. Where is the value of qryKioskNum coming from? You have 16 query objects and you want to dynamically select which is referenced in another query object? I don't think that is possible.

– June7
Jan 2 at 17:55













I added quite a bit to clarify my exact question. I also included the SQL statement that you asked for.

– jawohl
Jan 2 at 18:24





I added quite a bit to clarify my exact question. I also included the SQL statement that you asked for.

– jawohl
Jan 2 at 18:24












2 Answers
2






active

oldest

votes


















0














In msaccess, create a PassThru query (because it retains the multi-line nice format).



Create // QueryDesign // Close // rightClick // SQLSpecific // PassThru



Paste in the following sql.



INSERT INTO kxxdisprejstat

(kxxstatdate,
kxxbillcount1,
kxxbillcount2,
kxxbillcount3,
kxxbillcount4,
kxxbillcount5,
kxxbillcount6,
kxxbillrej1,
kxxbillrej2,
kxxbillrej3,
kxxbillrej4,
kxxbillrej5,
kxxbillrej6)

SELECT Datevalue([responseframes] ! [dispdatetime]) AS [Date],
SUM(responseframes.billcount1) AS SumOfbillCount1,
SUM(responseframes.billcount2) AS SumOfbillCount2,
SUM(responseframes.billcount3) AS SumOfbillCount3,
SUM(responseframes.billcount4) AS SumOfbillCount4,
SUM(responseframes.billcount5) AS SumOfbillCount5,
SUM(responseframes.billcount6) AS SumOfbillCount6,
SUM(responseframes.billrej1) AS SumOfBillRej1,
SUM(responseframes.billrej2) AS SumOfBillRej2,
SUM(responseframes.billrej3) AS SumOfBillRej3,
SUM(responseframes.billrej4) AS SumOfBillRej4,
SUM(responseframes.billrej5) AS SumOfbillRej5,
SUM(responseframes.billrej6) AS SumOfbillRej6

FROM responseframes,
lastkxxstatdate

WHERE (( ( responseframes.kioskid ) = "kxx" ))

GROUP BY Datevalue([responseframes] ! [dispdatetime])

HAVING (( ( Datevalue([responseframes] ! [dispdatetime]) )
> Max([lastkxxstatdate]![kxxlastdate]) ))

ORDER BY Datevalue([responseframes] ! [dispdatetime]);


Name it kxxInsert (or some such, using kxx to say that it is generalized).



Then add this to the program



Sub getKxx()
Dim qrykiosknum As Integer ' temp here to have something
qrykiosknum = 3 ' temp here for an example

Dim kxxSQL As String, strSQL As String
kxxSQL = CurrentDb.QueryDefs("kxxInsert").SQL
strSQL = Replace(kxxSQL, "kxx", "k" & qrykiosknum)
'MsgBox (strSQL) ' it is too big to see all of it
Debug.Print strSQL

' then run strSQL


End Sub


Having dynamic tablename in MSAccess or MSSQLServer is possible when the Replace is done before executing the SQL.






share|improve this answer


























  • This worked! Although I had to remove the double quotes in the Max function under the Having section.

    – jawohl
    Jan 2 at 20:01











  • @jawohl I just fixed my copy also. Glad you like it

    – donPablo
    Jan 2 at 20:12



















0














I doubt you can make this work by using a query with a parameter. You are much better off using VBA. Use InputBox to get the variable portion of the query and DoCmd.RunSQL to run the query.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54010382%2fparameter-inside-identifier%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    In msaccess, create a PassThru query (because it retains the multi-line nice format).



    Create // QueryDesign // Close // rightClick // SQLSpecific // PassThru



    Paste in the following sql.



    INSERT INTO kxxdisprejstat

    (kxxstatdate,
    kxxbillcount1,
    kxxbillcount2,
    kxxbillcount3,
    kxxbillcount4,
    kxxbillcount5,
    kxxbillcount6,
    kxxbillrej1,
    kxxbillrej2,
    kxxbillrej3,
    kxxbillrej4,
    kxxbillrej5,
    kxxbillrej6)

    SELECT Datevalue([responseframes] ! [dispdatetime]) AS [Date],
    SUM(responseframes.billcount1) AS SumOfbillCount1,
    SUM(responseframes.billcount2) AS SumOfbillCount2,
    SUM(responseframes.billcount3) AS SumOfbillCount3,
    SUM(responseframes.billcount4) AS SumOfbillCount4,
    SUM(responseframes.billcount5) AS SumOfbillCount5,
    SUM(responseframes.billcount6) AS SumOfbillCount6,
    SUM(responseframes.billrej1) AS SumOfBillRej1,
    SUM(responseframes.billrej2) AS SumOfBillRej2,
    SUM(responseframes.billrej3) AS SumOfBillRej3,
    SUM(responseframes.billrej4) AS SumOfBillRej4,
    SUM(responseframes.billrej5) AS SumOfbillRej5,
    SUM(responseframes.billrej6) AS SumOfbillRej6

    FROM responseframes,
    lastkxxstatdate

    WHERE (( ( responseframes.kioskid ) = "kxx" ))

    GROUP BY Datevalue([responseframes] ! [dispdatetime])

    HAVING (( ( Datevalue([responseframes] ! [dispdatetime]) )
    > Max([lastkxxstatdate]![kxxlastdate]) ))

    ORDER BY Datevalue([responseframes] ! [dispdatetime]);


    Name it kxxInsert (or some such, using kxx to say that it is generalized).



    Then add this to the program



    Sub getKxx()
    Dim qrykiosknum As Integer ' temp here to have something
    qrykiosknum = 3 ' temp here for an example

    Dim kxxSQL As String, strSQL As String
    kxxSQL = CurrentDb.QueryDefs("kxxInsert").SQL
    strSQL = Replace(kxxSQL, "kxx", "k" & qrykiosknum)
    'MsgBox (strSQL) ' it is too big to see all of it
    Debug.Print strSQL

    ' then run strSQL


    End Sub


    Having dynamic tablename in MSAccess or MSSQLServer is possible when the Replace is done before executing the SQL.






    share|improve this answer


























    • This worked! Although I had to remove the double quotes in the Max function under the Having section.

      – jawohl
      Jan 2 at 20:01











    • @jawohl I just fixed my copy also. Glad you like it

      – donPablo
      Jan 2 at 20:12
















    0














    In msaccess, create a PassThru query (because it retains the multi-line nice format).



    Create // QueryDesign // Close // rightClick // SQLSpecific // PassThru



    Paste in the following sql.



    INSERT INTO kxxdisprejstat

    (kxxstatdate,
    kxxbillcount1,
    kxxbillcount2,
    kxxbillcount3,
    kxxbillcount4,
    kxxbillcount5,
    kxxbillcount6,
    kxxbillrej1,
    kxxbillrej2,
    kxxbillrej3,
    kxxbillrej4,
    kxxbillrej5,
    kxxbillrej6)

    SELECT Datevalue([responseframes] ! [dispdatetime]) AS [Date],
    SUM(responseframes.billcount1) AS SumOfbillCount1,
    SUM(responseframes.billcount2) AS SumOfbillCount2,
    SUM(responseframes.billcount3) AS SumOfbillCount3,
    SUM(responseframes.billcount4) AS SumOfbillCount4,
    SUM(responseframes.billcount5) AS SumOfbillCount5,
    SUM(responseframes.billcount6) AS SumOfbillCount6,
    SUM(responseframes.billrej1) AS SumOfBillRej1,
    SUM(responseframes.billrej2) AS SumOfBillRej2,
    SUM(responseframes.billrej3) AS SumOfBillRej3,
    SUM(responseframes.billrej4) AS SumOfBillRej4,
    SUM(responseframes.billrej5) AS SumOfbillRej5,
    SUM(responseframes.billrej6) AS SumOfbillRej6

    FROM responseframes,
    lastkxxstatdate

    WHERE (( ( responseframes.kioskid ) = "kxx" ))

    GROUP BY Datevalue([responseframes] ! [dispdatetime])

    HAVING (( ( Datevalue([responseframes] ! [dispdatetime]) )
    > Max([lastkxxstatdate]![kxxlastdate]) ))

    ORDER BY Datevalue([responseframes] ! [dispdatetime]);


    Name it kxxInsert (or some such, using kxx to say that it is generalized).



    Then add this to the program



    Sub getKxx()
    Dim qrykiosknum As Integer ' temp here to have something
    qrykiosknum = 3 ' temp here for an example

    Dim kxxSQL As String, strSQL As String
    kxxSQL = CurrentDb.QueryDefs("kxxInsert").SQL
    strSQL = Replace(kxxSQL, "kxx", "k" & qrykiosknum)
    'MsgBox (strSQL) ' it is too big to see all of it
    Debug.Print strSQL

    ' then run strSQL


    End Sub


    Having dynamic tablename in MSAccess or MSSQLServer is possible when the Replace is done before executing the SQL.






    share|improve this answer


























    • This worked! Although I had to remove the double quotes in the Max function under the Having section.

      – jawohl
      Jan 2 at 20:01











    • @jawohl I just fixed my copy also. Glad you like it

      – donPablo
      Jan 2 at 20:12














    0












    0








    0







    In msaccess, create a PassThru query (because it retains the multi-line nice format).



    Create // QueryDesign // Close // rightClick // SQLSpecific // PassThru



    Paste in the following sql.



    INSERT INTO kxxdisprejstat

    (kxxstatdate,
    kxxbillcount1,
    kxxbillcount2,
    kxxbillcount3,
    kxxbillcount4,
    kxxbillcount5,
    kxxbillcount6,
    kxxbillrej1,
    kxxbillrej2,
    kxxbillrej3,
    kxxbillrej4,
    kxxbillrej5,
    kxxbillrej6)

    SELECT Datevalue([responseframes] ! [dispdatetime]) AS [Date],
    SUM(responseframes.billcount1) AS SumOfbillCount1,
    SUM(responseframes.billcount2) AS SumOfbillCount2,
    SUM(responseframes.billcount3) AS SumOfbillCount3,
    SUM(responseframes.billcount4) AS SumOfbillCount4,
    SUM(responseframes.billcount5) AS SumOfbillCount5,
    SUM(responseframes.billcount6) AS SumOfbillCount6,
    SUM(responseframes.billrej1) AS SumOfBillRej1,
    SUM(responseframes.billrej2) AS SumOfBillRej2,
    SUM(responseframes.billrej3) AS SumOfBillRej3,
    SUM(responseframes.billrej4) AS SumOfBillRej4,
    SUM(responseframes.billrej5) AS SumOfbillRej5,
    SUM(responseframes.billrej6) AS SumOfbillRej6

    FROM responseframes,
    lastkxxstatdate

    WHERE (( ( responseframes.kioskid ) = "kxx" ))

    GROUP BY Datevalue([responseframes] ! [dispdatetime])

    HAVING (( ( Datevalue([responseframes] ! [dispdatetime]) )
    > Max([lastkxxstatdate]![kxxlastdate]) ))

    ORDER BY Datevalue([responseframes] ! [dispdatetime]);


    Name it kxxInsert (or some such, using kxx to say that it is generalized).



    Then add this to the program



    Sub getKxx()
    Dim qrykiosknum As Integer ' temp here to have something
    qrykiosknum = 3 ' temp here for an example

    Dim kxxSQL As String, strSQL As String
    kxxSQL = CurrentDb.QueryDefs("kxxInsert").SQL
    strSQL = Replace(kxxSQL, "kxx", "k" & qrykiosknum)
    'MsgBox (strSQL) ' it is too big to see all of it
    Debug.Print strSQL

    ' then run strSQL


    End Sub


    Having dynamic tablename in MSAccess or MSSQLServer is possible when the Replace is done before executing the SQL.






    share|improve this answer















    In msaccess, create a PassThru query (because it retains the multi-line nice format).



    Create // QueryDesign // Close // rightClick // SQLSpecific // PassThru



    Paste in the following sql.



    INSERT INTO kxxdisprejstat

    (kxxstatdate,
    kxxbillcount1,
    kxxbillcount2,
    kxxbillcount3,
    kxxbillcount4,
    kxxbillcount5,
    kxxbillcount6,
    kxxbillrej1,
    kxxbillrej2,
    kxxbillrej3,
    kxxbillrej4,
    kxxbillrej5,
    kxxbillrej6)

    SELECT Datevalue([responseframes] ! [dispdatetime]) AS [Date],
    SUM(responseframes.billcount1) AS SumOfbillCount1,
    SUM(responseframes.billcount2) AS SumOfbillCount2,
    SUM(responseframes.billcount3) AS SumOfbillCount3,
    SUM(responseframes.billcount4) AS SumOfbillCount4,
    SUM(responseframes.billcount5) AS SumOfbillCount5,
    SUM(responseframes.billcount6) AS SumOfbillCount6,
    SUM(responseframes.billrej1) AS SumOfBillRej1,
    SUM(responseframes.billrej2) AS SumOfBillRej2,
    SUM(responseframes.billrej3) AS SumOfBillRej3,
    SUM(responseframes.billrej4) AS SumOfBillRej4,
    SUM(responseframes.billrej5) AS SumOfbillRej5,
    SUM(responseframes.billrej6) AS SumOfbillRej6

    FROM responseframes,
    lastkxxstatdate

    WHERE (( ( responseframes.kioskid ) = "kxx" ))

    GROUP BY Datevalue([responseframes] ! [dispdatetime])

    HAVING (( ( Datevalue([responseframes] ! [dispdatetime]) )
    > Max([lastkxxstatdate]![kxxlastdate]) ))

    ORDER BY Datevalue([responseframes] ! [dispdatetime]);


    Name it kxxInsert (or some such, using kxx to say that it is generalized).



    Then add this to the program



    Sub getKxx()
    Dim qrykiosknum As Integer ' temp here to have something
    qrykiosknum = 3 ' temp here for an example

    Dim kxxSQL As String, strSQL As String
    kxxSQL = CurrentDb.QueryDefs("kxxInsert").SQL
    strSQL = Replace(kxxSQL, "kxx", "k" & qrykiosknum)
    'MsgBox (strSQL) ' it is too big to see all of it
    Debug.Print strSQL

    ' then run strSQL


    End Sub


    Having dynamic tablename in MSAccess or MSSQLServer is possible when the Replace is done before executing the SQL.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 2 at 20:09

























    answered Jan 2 at 19:10









    donPablodonPablo

    1,0831813




    1,0831813













    • This worked! Although I had to remove the double quotes in the Max function under the Having section.

      – jawohl
      Jan 2 at 20:01











    • @jawohl I just fixed my copy also. Glad you like it

      – donPablo
      Jan 2 at 20:12



















    • This worked! Although I had to remove the double quotes in the Max function under the Having section.

      – jawohl
      Jan 2 at 20:01











    • @jawohl I just fixed my copy also. Glad you like it

      – donPablo
      Jan 2 at 20:12

















    This worked! Although I had to remove the double quotes in the Max function under the Having section.

    – jawohl
    Jan 2 at 20:01





    This worked! Although I had to remove the double quotes in the Max function under the Having section.

    – jawohl
    Jan 2 at 20:01













    @jawohl I just fixed my copy also. Glad you like it

    – donPablo
    Jan 2 at 20:12





    @jawohl I just fixed my copy also. Glad you like it

    – donPablo
    Jan 2 at 20:12













    0














    I doubt you can make this work by using a query with a parameter. You are much better off using VBA. Use InputBox to get the variable portion of the query and DoCmd.RunSQL to run the query.






    share|improve this answer




























      0














      I doubt you can make this work by using a query with a parameter. You are much better off using VBA. Use InputBox to get the variable portion of the query and DoCmd.RunSQL to run the query.






      share|improve this answer


























        0












        0








        0







        I doubt you can make this work by using a query with a parameter. You are much better off using VBA. Use InputBox to get the variable portion of the query and DoCmd.RunSQL to run the query.






        share|improve this answer













        I doubt you can make this work by using a query with a parameter. You are much better off using VBA. Use InputBox to get the variable portion of the query and DoCmd.RunSQL to run the query.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 2 at 18:48









        SunKnight0SunKnight0

        2,468167




        2,468167






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54010382%2fparameter-inside-identifier%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas