locked
MS Access 2003 Issue RRS feed

  • Question

  • We  are inserting the data in the access database but we are getting error. Please

    INSERT INTO viewRepairRecs (RepairRecID,ServiceCallID,NumberOfTechs, LaborHours, Recommendations,Severity,IsCheckedIn)
                          VALUES ((select count(*)+1 from viewRepairRecs), @ServiceCallID,@NumberOfTechs,@LaborHours,@Recommendations,@Severity,no)

    I think error occurring by this line

    (select count(*)+1 from viewRepairRecs)

    We need to insert value  TotalRecord+1 for the RepairRecID column. How to possible in the access database or we can set default value formula for this column. How?

    Please help me.

    Monday, December 5, 2016 8:09 AM

Answers

  • Hi AnkitKumar2016,

    I can see that you had use the sub query in the main query.

    it will not work.

    you have to use DCount Function to get count from another table and use it in insert query.

    INSERT INTO [number] ( [no] )values(DCount("*","demo"));
    

    Reference:

    DCount Function

    above query is working and tested on my side.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, December 6, 2016 5:48 AM

All replies

  • Hi AnkitKumar2016,

    Thanks for posting here.

    This forum is about WPF development. For your case about Access, I will move it to Access for Developers forum for suitable help.

    Your understanding and cooperation will be grateful.

    Best Regards,

    Yohann Lu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, December 6, 2016 2:44 AM
  • Hi AnkitKumar2016,

    I can see that you had use the sub query in the main query.

    it will not work.

    you have to use DCount Function to get count from another table and use it in insert query.

    INSERT INTO [number] ( [no] )values(DCount("*","demo"));
    

    Reference:

    DCount Function

    above query is working and tested on my side.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, December 6, 2016 5:48 AM