Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 28th, 2009, 06:01 PM
Registered User
 
Join Date: Dec 2009
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default Update table from form

Hello and Happy New Year!

I (a retired, unpaid volunteer) have lurked and searched and tried what I learned here, but only know enough to know that I need your help. And I thank you ALL for helping me and others here.

I have several tables of equipment assigned for certain circumstances.

Table: tSelectionSets
Fields are:
tSelectionSets_ID AutoNumber LongInteger Primary Key
SelName Text Set’s Nickname
Sel_Car_ID Number LongInteger Lookups to tCars tCar_ID
(more fields for Truck, Generators, Compressors, etc. – all long Intergers)

Table: tCars
Fields are:
tCar_ID AutoNumber LongInteger Primary Key
CarNickName Text Car’s Nickname
(many fields ie. VIN, inspection info, license, etc…..)

In form (fSelectionSets) I select Set (#3 – TestSetThree) which has no car (Sel_Car_ID = 0) and from there via a command button open form (fSelectCar) and choose (tCar_ID = 4) (CarNickName = Fred’s pickup).

Now I click command button (CmdSaveThisRec) to TRY to update record 3 of Table: tSelectionSets.

This table is NOT updated.

My code is:
code
Private Sub CmdSaveThisRec_Click()
On Error GoTo Err_CmdSaveThisRec_Click

strSQL = "UPDATE tSelectionSets" & _
" SET tSelectionSets.Sel_Car_ID = " & Forms![fSelectCar]![txtSel_Car_ID] & _
" WHERE tSelectionSets.tSelectionSets_ID = " & Forms![fSelectionSets]![txttSelectionSets_ID]

DoCmd.RunSQL strSQL

Exit_CmdSaveThisRec_Click:
Exit Sub

Err_CmdSaveThisRec_Click:
MsgBox Err.Description
Resume Exit_CmdSaveThisRec_Click

End Sub
/code

Thank you for your assistance.
-- Fred
 
Old December 29th, 2009, 09:01 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Hi there.. if you receive no error, then your query is not trying to update what you think.
Could you debug the Query String and see if the parameters are correct??

Once you do that, can you manually try the query to see if something happens???
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
The Following User Says Thank You to gbianchi For This Useful Post:
FKlusmann (December 29th, 2009)
 
Old December 29th, 2009, 02:57 PM
Registered User
 
Join Date: Dec 2009
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thank you.

I did get it to work, but do not understand why.

Quote:
....your query is not trying to update what you think.
Could you debug the Query String and see if the parameters are correct?
I could not figure our how to debug this. Me Access uses Visual Basic 6.3 and its debug and compile run without showing an error.

I changed the statement to
Quote:
Private Sub CmdSaveThisRec_Click()
On Error GoTo Err_CmdSaveThisRec_Click

strSQL = "UPDATE tSelectionSets" & _
" SET Sel_Car_ID = " & Me.[txtSel_Car_ID] & _
" WHERE tSelectionSets_ID = " & Forms![fSelectionSets]![txttSelectionSets_ID]

DoCmd.RunSQL strSQL

Exit_CmdSaveThisRec_Click:
Exit Sub

Err_CmdSaveThisRec_Click:
MsgBox Err.Description
Resume Exit_CmdSaveThisRec_Click

End Sub
I really don't understand why replacing
Forms![fSelectCar]![txtSel_Car_ID]
with
Me.[txtSel_Car_ID]
made this work, but it does.

Any education would be appreciated.

Thanks again!
¡Feliz Año Nuevo!

-- Fred





Similar Threads
Thread Thread Starter Forum Replies Last Post
Update table using SQL query from form pater53 Access VBA 4 January 24th, 2007 11:24 AM
Update Table From Form ksbrain Access 2 January 9th, 2007 01:49 PM
Update parent table with the sum of child table gbrown SQL Language 2 November 9th, 2004 07:53 AM
Update table from form leeloo Access VBA 1 June 28th, 2004 11:50 AM
Access update table from form values trevander Access VBA 2 April 28th, 2004 03:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.