Solved

SQL Update Statement

Posted on 2011-02-28
3
505 Views
Last Modified: 2012-05-11
Hi,

I'm trying to update a table that will be used in other queries; using data that the user has selected on a combo box form.

I don't get an error at all but when I open the table, it is blank.

Below is my code, can anyone spot where I am going wrong?
.................................................................
Private Sub CmdOK_Click()

DoCmd.SetWarnings False


If IsNull(cbovaldate) Or IsNull(cboNZRG0date) Or IsNull(cboNBDate) Or IsNull(cboBOYStart) Then
    MsgBox "Valuation dates may not be blank!", vbExclamation + vbOKOnly
    Exit Sub
    End If
   
   

DoCmd.RunSQL "UPDATE zzvaldate SET zzvaldate.Valuation_Date = " & Forms!Update_Valdate!cbovaldate & " ;"

DoCmd.RunSQL "Update zzvaldate set zzvaldate.Valuation_Date_yyyymmdd = " & Forms!Update_Valdate!cboNZRG0date & " ; "

DoCmd.RunSQL "Update zzvaldate set zzvaldate.NB_start_date = " & Forms!Update_Valdate!cboNBDate & " ; "

DoCmd.RunSQL "Update zzvaldate set zzvaldate.BOY_Date = " & Forms!Update_Valdate!cboBOYDate & " ; "

MsgBox "Valuation dates have been updated", vbOKOnly

DoCmd.Close acForm, "Update_Valdate"

DoCmd.SetWarnings True


End Sub
0
Comment
Question by:DB_newbie_NZ
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 250 total points
ID: 35002950
if Valuation_Date field is Date/time Data type, use this

DoCmd.RunSQL "UPDATE zzvaldate SET zzvaldate.Valuation_Date = #" & Forms!Update_Valdate!cbovaldate & "# ;"

if Valuation_Date field is Text Data type, use this

DoCmd.RunSQL "UPDATE zzvaldate SET zzvaldate.Valuation_Date = '" & Forms!Update_Valdate!cbovaldate & "'"
0
 

Author Comment

by:DB_newbie_NZ
ID: 35003064
Thanks capricorn1, I've tried that but it still doesn't work.

The dates in the table are date/time format except for one which is long integer because it is in yyyymmdd format.

The combo box is taking the possbile valuation dates from a table which in turn has formates that match the table to be updated.

I have several of these forms and none of the update queries are working, including the one where I enter text into a text box.
0
 

Author Comment

by:DB_newbie_NZ
ID: 35003211
Capricorn1, your solution works, thanks a mill! The table being updated was null but when i put in dummy dates in there, the table updated.

So I guess  I must specify to update even when the table is null?

Ok, so now I've updated my dates successfully but say next time I want to open the Update_date form just to make sure my valuation dates are correct. Do i have to change the combo boxes to bound so that data entered will be saved in the combo box till I update it?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question