Update table with date and number

I'm trying to update a table with the current date and the current user ID 
but I keep getting a syntax error. Could somebody check my code and tell me 
what I'm doing wrong?

Dim strUserID As Integer

strUserID = DLookup("UserID", "q_GetUser")

CurrentDb.Execute "UPDATE (pt_PurchaseOrders) SET 
pt_PurchaseOrders.CancelledDate = Date(), pt_PurchaseOrders.CancelledBy = 
strUserID WHERE pt_PurchaseOrders.PONumber = " & Me.PONumber
  
0
Utf
12/15/2009 2:16:01 PM
access.forms 6864 articles. 2 followers. Follow

3 Replies
846 Views

Similar Articles

[PageSpeed] 35

JB -

Two things - you want the RunSQL statement (not the Execute), and also the 
strUserID needs to have single quotes put around the text as a delimeter.  
Try this:

DoCmd.RunSQL "UPDATE (pt_PurchaseOrders) SET pt_PurchaseOrders.CancelledDate 
= Date(), pt_PurchaseOrders.CancelledBy = '" & strUserID & "' WHERE 
pt_PurchaseOrders.PONumber = " & Me.PONumber

If the PONumber is a text field, it would need the delimeters also.
-- 
Daryl S


"JB" wrote:

> I'm trying to update a table with the current date and the current user ID 
> but I keep getting a syntax error. Could somebody check my code and tell me 
> what I'm doing wrong?
> 
> Dim strUserID As Integer
> 
> strUserID = DLookup("UserID", "q_GetUser")
> 
> CurrentDb.Execute "UPDATE (pt_PurchaseOrders) SET 
> pt_PurchaseOrders.CancelledDate = Date(), pt_PurchaseOrders.CancelledBy = 
> strUserID WHERE pt_PurchaseOrders.PONumber = " & Me.PONumber
>   
0
Utf
12/15/2009 2:31:01 PM
Thanks Daryl.

It works perfectly now.


"Daryl S" wrote:

> JB -
> 
> Two things - you want the RunSQL statement (not the Execute), and also the 
> strUserID needs to have single quotes put around the text as a delimeter.  
> Try this:
> 
> DoCmd.RunSQL "UPDATE (pt_PurchaseOrders) SET pt_PurchaseOrders.CancelledDate 
> = Date(), pt_PurchaseOrders.CancelledBy = '" & strUserID & "' WHERE 
> pt_PurchaseOrders.PONumber = " & Me.PONumber
> 
> If the PONumber is a text field, it would need the delimeters also.
> -- 
> Daryl S
> 
> 
> "JB" wrote:
> 
> > I'm trying to update a table with the current date and the current user ID 
> > but I keep getting a syntax error. Could somebody check my code and tell me 
> > what I'm doing wrong?
> > 
> > Dim strUserID As Integer
> > 
> > strUserID = DLookup("UserID", "q_GetUser")
> > 
> > CurrentDb.Execute "UPDATE (pt_PurchaseOrders) SET 
> > pt_PurchaseOrders.CancelledDate = Date(), pt_PurchaseOrders.CancelledBy = 
> > strUserID WHERE pt_PurchaseOrders.PONumber = " & Me.PONumber
> >   
0
Utf
12/15/2009 2:53:02 PM
JB,

Just for the record, the "Currentdb.Execute" is perfectly fine to use when 
trying to run any action type query. 

To validate this, try the new updated sql statement provided byt Daryl S 
with the "Currentdb.Execute" statement. 

Not that it really matters that much but I felt that you and others should 
know.

-----
HTH
Mr. B
http://www.askdoctoraccess.com/
Doctor Access Downloads Page: 
http://www.askdoctoraccess.com/DownloadPage.htm


"JB" wrote:

> Thanks Daryl.
> 
> It works perfectly now.
> 
> 
> "Daryl S" wrote:
> 
> > JB -
> > 
> > Two things - you want the RunSQL statement (not the Execute), and also the 
> > strUserID needs to have single quotes put around the text as a delimeter.  
> > Try this:
> > 
> > DoCmd.RunSQL "UPDATE (pt_PurchaseOrders) SET pt_PurchaseOrders.CancelledDate 
> > = Date(), pt_PurchaseOrders.CancelledBy = '" & strUserID & "' WHERE 
> > pt_PurchaseOrders.PONumber = " & Me.PONumber
> > 
> > If the PONumber is a text field, it would need the delimeters also.
> > -- 
> > Daryl S
> > 
> > 
> > "JB" wrote:
> > 
> > > I'm trying to update a table with the current date and the current user ID 
> > > but I keep getting a syntax error. Could somebody check my code and tell me 
> > > what I'm doing wrong?
> > > 
> > > Dim strUserID As Integer
> > > 
> > > strUserID = DLookup("UserID", "q_GetUser")
> > > 
> > > CurrentDb.Execute "UPDATE (pt_PurchaseOrders) SET 
> > > pt_PurchaseOrders.CancelledDate = Date(), pt_PurchaseOrders.CancelledBy = 
> > > strUserID WHERE pt_PurchaseOrders.PONumber = " & Me.PONumber
> > >   
0
Utf
12/15/2009 6:55:07 PM
Reply:

Similar Artilces:

Problem with Script Updating
I am using a script to update the “1099 Type” field for Master Vendor table. The script basically is a basic if-then statement. This script is run “Before Document Commit” and it’s not updating correctly, its flip-flopping the results. When the script is set to run Before Document Commit I have the “Destination mapping” field “1099 Type” set to “Use Script”. Script below: If SourceFields("Send 1099") = "N" Then DestinationFields("Options.1099 Type").Value = 1 Else DestinationFields("Options.1099 Type").Value = 4 End If I have also tried this s...

pivot table with dynamic base data
hiya, im trying to create a pivot table where I can change my base data (inserting or deleting rows of data) and still have this reflected in the pivot table. My solution was to use entire columns as my range for input to the pivotTable, but this means including blank rows which seems to muck up the calculations. I cant think how else i can allow for new rows to be added to the base data anyone got any ideas how to do this? thanks loads for your help! You can use a dynamic range as the source. There are instructions here: http://www.contextures.com/xlPivot01.html bb wrote: > hiy...

Update for MS Money 2005?
I have Money 2005. Is there an update to MS Money for Canadian users? Thanks in advance for any answers. We need a bit more information! Are you having problems with M2005 or is this just a post-Christmas/New Year random query when you are trying to get away from the in-laws? -- Regards Bob Peel, Microsoft MVP - Money For unofficial FAQs see http://money.mvps.org/ or http://umpmfaq.info/ I do not respond to any emails that I have not specifically asked for. "Daniel" <Daniel@discussions.microsoft.com> wrote in message news:E86EAB89-21DE-4505-ACAD-647278D736BD@microso...

updating sheets based on data in first sheet
Another payroll question, I have a workbook that contains 26 sheets, one for each bi-weekl payroll period. I would like to set it up so when i add a new employe the rest of the sheets also update automatically with that employee name and information. I have been able to acheive this to a limited degree using th =sheet1!a1 formula, but this only updates the info in the first cel and particularly the first column. I would like to acheive this using the first sheet, since at th end of the year I would like to be able to calculate ytd figure easily. Thank -- Message posted from http://www.Exc...

Error: Can't clean up the following tables: PriceLevel. 02-13-05
Hello all, using CRM 1.2 on a win2k3 server we get this error in the application event log: Source: MSCRMDeletionService Event ID: 5895 - Error: Can't clean up the following tables: PriceLevel. Category: none User: n/a Computer: our_exchange_server ooppps, I forgot, of course many thanks in advance for any tip! ...

Publisher 2007 and Microsoft Updates
I created a newsletter yesterday - everything fine - use Publisher all the time. Then an automatic update came down this morning and I can't open the file - it says "Publisher cannot open file" Other documents in Publisher are opening - any ideas? http://support.microsoft.com/kb/972566/ -- JoAnn Paules MVP Microsoft [Publisher] Tech Editor for "Microsoft Publisher 2007 For Dummies" "Kim" <Kim@discussions.microsoft.com> wrote in message news:8754339B-99DC-4D09-83AD-6B34D8215274@microsoft.com... >I created a newsletter yesterday - everythin...

Microsoft Update only updates Windows Defender
iacrosoft Update only updates Windows Defender - I have to use Belarc Advisor to get a list of missing updates, and then go to the Microsoft Download Center to search for the missing updates and download and install them one at a time. I have Windows XP Home SP3, with Microsoft Update set to automatic download - can anyone tell me why I do not get all the necessary upadtes? Is this a sudden, new problem? When was Automatic Updates last working? Can you update manually via http://windowsupdate.microsoft.com? Any chance you've got a beta build of WinXP SP3 installed? What...

MS can't even get the release date right
Microsoft CRM has been a major disappointment in most every aspect. Now, they've failed again with the CRM product by delaying the CRM 2005 release until 4th Quarter. Some might say that this is a good thing so that it's a better product, but MS should have it more together than to announce a ship date they can't fulfill. Very frustrating that we have to continue on with this inferior version 1 product even longer. -- Brandon Smith IT Director Presentations Direct - Specialized Office Equipment & Supplies http://www.presentationsdirect.com So what causes you to ca...

From temporary table to master table and then join this in junction table
Hello, I have imported two spreadsheets from excel to two temporary tables called "import_tbl_contract" and "import_tbl_products". I do this on daily basis and import many spreadsheets. I end up with these data: [import_tbl_contract] contract_number contract_title start_date end_date [import_tbl_products] product_number product_text price I now append these data to the following two tables: [tbl_contract] contract_id (PK) contract_title start_date end_date e.g. 1; Syringes and needles; 01-01-2010; 31-12-2010 [tbl_products] product_id ...

Excel 2010 Slicer Connection / Pivot Table Problem
Working in Excel 2010 beta. I have two pivot tables created from different SSAS cubes. I have PowerPivot add in installed, but not using it for this project. The two pivot tables both share several similar dimensions. When I try to connect a given slicer to both pivot tables, the 2nd pivot table is not available in the "Pivot Table Connections" window. The only pivot table listed in the "Pivot Table Connections" is the one for which the slicer was originally created. All of the posts I've seen so far say that all the pivot tables in the workbook should appear...

Multiple date select calender
I need a calender for MFC in which i can select multiple dates similar to what is there in calender of outlook 2003. Also I need the functionality to be able to select the days i.e. sunday, monday, etc. Is there some activex available freely which i can use. Or is it possible to achieve the same by subclassing the existing CMonthCalCtrl in MFC. Please guide me. Thanks in Anticipation Software Engineer wrote: > I need a calender for MFC in which i can select multiple dates similar to > what is there in calender of outlook 2003. Also I need the functionality to > be able to sel...

Update question
Soory if this is the wrong place to ask this, but cannot find a NG proper to Windows 7. I currently run Windows Vista and am getting tired of Vista's decision to tell me that it is going to shut down in less than a minute. So have decided to upgrade to Windows &. I note that I can purchase an upgrade versiom for 64 quid from Amazon or an apparently full version of Windows 7 Home premium for 89 quid. My question is this - If I buy the upgrade version will I only be able to load it on a new PC in the future if I already have windows Vista installed? i.e For any future cl...

Excel cells changes number format automatically
I am using Excel 2007. Many of the cells I am working on are in general format where I store various numbers for analysis. These values change itself to date format occassionally creating whole lot of work for me to change them back to general format. How can I solve this issue? Also in my pivot table, my source data is in general format. Still when I click on sub total in any catagory in the table to find details about it, formats are changed date format in the new sheet it pops up. Can someone help resolve this issue. ...

Outlook 2003 died mysteriously after update
Setup in a nutshell... System: Lenovo T500 laptop OS: Vista Business SP1 32-bit Software: Office Outlook 2003 SP3 Problem... So I'm using this setup for over a year, everything OK. Yesterday I did two things and now Outlook dies (quietly, sans error message) immediately after startup. It show the splash screen, displays my inbox, and *poof* disappears. What I did earlier... 1. Windows Update installed: KB9766662, KB979306, KB979099, KB975929 2. At the same time, while searching for another program to uninstall I stumbled upon (and uninstalled) Windows LIVE Toolbar and...

count matching numbers
This is probably simple but I'm about to go crazy trying to figure it out. Please help. I'm trying to count or total how many cells match another row of cells. For instance A4 = 23 B4 = 14 A5 = 34 B5 = 30 A6 = 39 B6 = 34 A7 = 48 B7 = 39 A8 = 53 B8 = 55 The answer I'm looking for is 2 because there are two cells that match. (A5 matches B6 and A6 matches B7) Thanks, mike Try ths: =SUMPRODUCT(--(ISNUMBER(MATCH(A4:A8,B4:B8,0)))) -- Biff Microsoft Excel MVP "Catfish" <mtblanton@gmail.com> wrote in message news:491279e0-18f9-4d29-a...

How update entity in post update?
I created a handler for Update post callout for Opportunity. I want update some fields of the opportunity on the PostUpdate. However, if I call the Update method of CRMOpportunity in the PostUpdate I will create a recursive post callout. Can somebody help me? Thank you for pay attention []'s Vin�cius Pitta Lima de Ara�jo You need to check the OrigObjectXML field to see what fields were updated and then act appropriately. Matt Parks MVP - Microsoft CRM ---------------------------------------- ---------------------------------------- On Wed, 4 Aug 2004 17:43:17 -0300, "Vin�cius ...

Cannot install update KB979906 for .NET Framework 1.1 SP1
Running : Windows XP media center edition SP3 Have tried installing KB979906 a few times and also downloaded update manually but cannot install this update. Receiving error 0x643.Is it safe to uninstall the .NET Framework 1.1 and re-install as possibly corrupt , without having to uninstall/re-install all other .NET frameworks 2 , 3 and 3.5 including the updates that go with them? .. Hello sherlockomes, you might want to look at the following kb article to see if this will help with the error 80070643. <http://windows.microsoft.com/en-US/windows-vista/Windows-Update-error...

When cells with dates don't format
I have some cells which contain dates. These dates are a link from another data source (Bloomberg) and when I try to formatt the cells, I cannot. They will only display the date in mm/dd/yyyy formatt. Any ideas? Thanks My first guess is that the cells are coming in as text. Look for an apostrophe (" ' ") in front of the data in the cell. If not, try using "text to columns" (select the entire column, click Data, Text to Columns, Finish). Then, attempt to re-format the cells (or entire column) as a date with the form that you want. Also, make sure ...

latest update too MSCFV2
Hi, I have MSCFV2 version 6.5.7825.0. Could someone inform me if this is the latest download? Looks like you have 6.5.7825.0 from 05/21/2006, but there is a newer version - 6.5.7831.0 from 06/01/2006. C. Smith Enso Technologies, Incorporated http://www.ensotech.com On Tue, 13 Jun 2006 04:25:02 -0700, Paul <Paul@discussions.microsoft.com> wrote: >Hi, > >I have MSCFV2 version 6.5.7825.0. Could someone inform me if this is the >latest download? Christopher Smith csmith@ensotech.com Enso Technologies, Incorporated http://www.ensotech.com Also - meant to post this in t...

Print record once, update Yes/No field verifiying print
I would like to print a group of records, then have a Yes/No field [Printed] updated in my Jobs table with an update query showing the records were printed. Then next time the report runs, In my query criteria I will test for True values on the Yes/No field. Then only the records with the Yes/No field marked No will print. Any suggestions? Thanks Tommyboy,there's more to this question than meets the eye. For an explanation of what's involved, see: Has the record been printed? at: http://allenbrowne.com/ser-72.html The article includes a free sample database that dem...

putting data into multiple tables
Using Access 2002 and would like to enter data into form which will then send to fields in multiple tables and update them. Can this be done and how need basic explanation Why do you want to send the data to different Tables? If The Tables all belong to the same Database. ie you're not dealing with different back-end systems, you probably have a serious normalization problem. Data should normally only have to be in one table in a relational database. Pieter "Phillipa" <Phillipa@discussions.microsoft.com> wrote in message news:994354EC-1216-4EEB-9CA9-D9F0880B03C5@mic...

Validation of numbers
hey I want to validate a cell so that it will only accept numbers, no text. These numbers could be decimals or whole numbers, therefore th Whole number option won't work. I tried the Decimal option, but i still allowed text. Can u help?? Thx KrisB_baco -- Message posted from http://www.ExcelForum.com One way (assume A1 is the cell) =ISNUMBER(A1) -- Regards, Peo Sjoblom "KrisB_bacon >" <<KrisB_bacon.11vmuj@excelforum-nospam.com> wrote in message news:KrisB_bacon.11vmuj@excelforum-nospam.com... > hey > > I want to validate a cell so that it will ...

Stop duplicate numbers
Hi I am setting up a spreadsheet to use as a basis for a database. How do I create a column of unique numbers that can be used as serial numbers? I need to ensure that all the numbers are not duplicated. Thanks Dave Put 1 in A1, 2 in A2, select A1:A2, go to the bottom right of the selection until the cursor becomes a black cross, click and drag down as much as you want. -- HTH RP (remove nothere from the email address if mailing direct) "Stig" <qazat@yahoo.com> wrote in message news:wIOdnflaPtux-3fcRVnyvQ@brightview.com... > Hi > I am setting up a spreadsheet t...

Dynamic Menu update
Hi All, I need to update a menu item dynamically, setting its SetCheck property to either true or false, based on a user operation. I am trying to do this from a custom function. Usually, the pCmdUI pointer is used. But how do I do it from another function? Thanks Your "other function" should change some setting. In your ON_UPDATE_COMMAND_UI handler, you should check that setting and call SetCheck as needed. -------------- Ajay Kalra ajaykalra@yahoo.com In addition to Ajay's response, this page may help you: http://msdn2.microsoft.com/en-us/library/6kc4d8f...

how to return a serial number to a date
Example: 40899 Is there a formula to convert the serial number 40899 above back to 12/22/2011? Thanks, Holly Format the cell as Date -- Biff Microsoft Excel MVP "Holly" <Holly@discussions.microsoft.com> wrote in message news:82F628DD-B506-4A72-B5AC-DF85265ADAB0@microsoft.com... > Example: 40899 > > Is there a formula to convert the serial number 40899 above back to > 12/22/2011? > > Thanks, Holly "Holly" wrote: > Is there a formula to convert the serial number 40899 > above back to 12/22/2011? It would h...