• Using a control’s value in an SQL statement (Access 97 / SR-2)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Using a control’s value in an SQL statement (Access 97 / SR-2)

    Author
    Topic
    #379220

    In a production tracking database that I maintain, I have 13 tables that represent different departments. Once a day we append time card data (estimated) into the corresponding departments table. We can then run reports that give us our unit costs and other pertinent business information.

    Because of the time consuming nature (due to my lack of access knowledge) we have never done updates to the time card data when the actuals are completed. Consequently we are always going to be a little bit off on our unit cost calculations.

    I have come up with an SQL statement that I can run that will simplify the process of deleting the estimated time card data and then we can append the actual data and re-run the reports. I am including the SQL statement I am using to do the updates.

        DoCmd.RunSQL "DELETE Embossing.*, Embossing.Date, Embossing.[Machine#] " & _
                "FROM Embossing " & _
                "WHERE (((Embossing.Date)=  date from forms control  ) " & _
                "AND ((Embossing.[Machine#])=99));", 0
    

    Could someone help me figure out a way to use a date in a form control inside as a variable inside my SQL statement.

    The way my process would work is, the user opens a form, enters the date of the data they are going to delete, and then click on a command button that fires a VB function that contains the above referenced SQL statement.

    My problem is getting the SQL statement to recognize the date value in the textbox control.

    The forms name is “frmRptDates46”, the date control is “box1” and the command button is “button1”.

    Any help is greatly appreciated.

    Viewing 0 reply threads
    Author
    Replies
    • #630700

      Just reference the box1 date like:
      Forms!frmRptDates46!box1

      Pat smile

      • #630708

        What a simple solution. Thank you for pointing it out to me. It worked like a charm.

        • #630710

          That’s ok, but a question I have is why do you have a table per department ? confused
          Pat cheers

          • #630721

            couple of reasons. 1) the things being tracked are different for each department, and more importantly 2) when I set this up several years ago, I didn’t know any better. I was an access beginner who was tasked with the project. Now I don’t have the time to do it better.

    Viewing 0 reply threads
    Reply To: Using a control’s value in an SQL statement (Access 97 / SR-2)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: