Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating a field dependent on a date range in Access with VisualBasic and SQL
    primarykey
    data
    text
    <p>A friend and I have been trying for hours with little progress to a get a piece of code right for an invoicing system we're designing as a project.</p> <p>We are trying to update the field InvoiceNo to a value (worked out earlier in the VisualBasic code), where the CustomerNo is the is a specific value and the FinishDate is between two dates. At first I was trying to use TO_DATE but then we realized that wasn't the same in the SQL that Access uses (after much searching).</p> <p>This has been the simple statement I've been using to just test and try to get something working to then translate into VisualBasic and put in our variables. It's a little easier to read so I thought I'd provide it.</p> <pre><code>UPDATE tblJob SET tblJob.InvoiceNo = '8' WHERE tblJob.CustomerNo = '1' AND (tblJob.FinishDate BETWEEN cdate(format('08/09/2013', '##/##/####')) AND cdate(format('03/10/2013', '##/##/####'))); </code></pre> <p>I have a feeling after looking at a few examples that our date is meant to be without an forward slashes. So I tried that and it wasn't working either.</p> <p>Here's the VisualBasic code that has come out of all of this, it's exactly the same but using some variables rather than our set values that I've been using for testing.</p> <pre><code>DoCmd.RunSQL ("UPDATE tblJob SET tblJob.InvoiceNo = '" &amp; newInvoiceNo &amp; "' WHERE tblJob.CustomerNo = '" &amp; VbCustNo &amp; "' AND (tblJob.FinishDate BETWEEN cdate(format('" &amp; Forms![frmMainMenu][txtFirstDate] &amp; "', '##/##/####')) AND cdate(format('" &amp; Forms![frmMainmenu][txtEndDate] &amp; "', '##/##/####')));") </code></pre> <p>We had a look at: <a href="https://stackoverflow.com/questions/1397232/convert-a-string-to-a-date-in-access">Convert a string to a date in Access</a> and it helped us realize that it was cdate(format()) rather than TO_DATE as it is in Oracle. But we just can't seem to get it to run properly, any help would be much appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload