Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA 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 April 12th, 2006, 07:31 AM
Registered User
 
Join Date: Apr 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Updating a field using a SELECT statement?

Hi everyone,

This is a really simple problem, but I I've only just started using Visual Basic this week so I don't know how to solve it.

I want to update a field in my main table using a value that I have selected from another table using a series of combo boxes. I choose a value (eg surname) in combo box 1, which in turn filters my second table so that in combo box 2 I have a choice of values (eg firstname). I would then like to write a module so that after update of firstname the primary key (foreign key in my main table) nameid is selected and is inserted into a textbox (nameid) bound to my main table.

I have the following code which shows what I want to do, but obviously it doesn't work because the UPDATE query contains a string...

Private Sub cbofirstname_AfterUpdate()

Set nameid As String

nameid = "SELECT tblname.nameid FROM tblename WHERE tblname.surname = '" & Me.cbosurname.Text & "' AND tblename.firstname = '" & Me.cbofirstname.Text & "';"

DoCmd.RunSQL (UPDATE tblmain SET tblnameid = & "nameid" & WHERE personid = " & Me.personid.Value & ";"

End Sub

Any ideas anyone?


 
Old April 12th, 2006, 10:23 AM
Friend of Wrox
 
Join Date: Dec 2005
Posts: 142
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Does the first command put the string you want in nameid?

The main problem I see is your second command (specifically where you put the quotes around nameid). It should be:
DoCmd.RunSQL (UPDATE tblmain SET tblnameid = '" & nameid & "' WHERE personid = '" & Me.personid.Value & "';"






Similar Threads
Thread Thread Starter Forum Replies Last Post
select Statement gregalb SQL Server 2000 3 January 15th, 2008 12:00 AM
Select from another select statement to a repeater simsen ASP.NET 2.0 Professional 0 May 2nd, 2007 04:34 PM
Updating a Date field based on another field arholly Access VBA 6 November 22nd, 2006 11:19 AM
DATA DISAPPEARED!when updating using SQL statement MilkPudding Classic ASP Databases 7 June 24th, 2004 08:28 AM
Select Statement jmss66 Oracle 1 May 27th, 2004 02:31 PM





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