PC Review


Reply
Thread Tools Rate Thread

Can VBA amend data in tables

 
 
Maxwell
Guest
Posts: n/a
 
      30th Apr 2010
Hi,

I have a subform which is linked to a Link Table (A) which controls
relationships between two parent tables (B) and (C). On the subform is a
button to delete record, which would delete the record in table (A).

What I want to do is add a line of code to the delete button that changes a
field in one of the parent tables (say, B) before it deletes the record in
table A.

I have been playing with the SQL UPDATE record but have not managed to get
it to work yet.

So, in the below code:

Table A is: not mentioned but is called LinkBedStd
Table B is: TableBed
Common Field is : BED#
Field on Table B is: Bed_Occupied?

Could it be that the '#' and '?' are causing the problems?

Current code for delete button is:

Private Sub Command27_Click()
On Error GoTo Err_Command27_Click
Dim x As String
x = Me!BED
y = MsgBox(x, vbInformation)

Dim mySQL As String
mySQL = "UPDATE TableBED"
mySQL = mySQL & "SET TableBED.BED_Occupied_ = False"
mySQL = mySQL & " WHERE TableBed.BED_ = x"

DoCmd.SetWarnings False
DoCmd.RunSQL mySQL
DpCmd.SetWarnings True

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord

Exit_Command27_Click:
Exit Sub

Err_Command27_Click:
MsgBox Err.Description
Resume Exit_Command27_Click

End Sub

Many thanks,
Max
 
Reply With Quote
 
 
 
 
Alex Dybenko
Guest
Posts: n/a
 
      30th Apr 2010
Hi,
try this:

mySQL = "UPDATE TableBED"
mySQL = mySQL & "SET TableBED.[BED_Occupied?] = False"
mySQL = mySQL & " WHERE TableBed.[BED#] = '" & x & "'"

--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com



"Maxwell" <(E-Mail Removed)> wrote in message
news:79CB6301-B421-4D97-8B13-(E-Mail Removed)...
> Hi,
>
> I have a subform which is linked to a Link Table (A) which controls
> relationships between two parent tables (B) and (C). On the subform is a
> button to delete record, which would delete the record in table (A).
>
> What I want to do is add a line of code to the delete button that changes
> a
> field in one of the parent tables (say, B) before it deletes the record in
> table A.
>
> I have been playing with the SQL UPDATE record but have not managed to get
> it to work yet.
>
> So, in the below code:
>
> Table A is: not mentioned but is called LinkBedStd
> Table B is: TableBed
> Common Field is : BED#
> Field on Table B is: Bed_Occupied?
>
> Could it be that the '#' and '?' are causing the problems?
>
> Current code for delete button is:
>
> Private Sub Command27_Click()
> On Error GoTo Err_Command27_Click
> Dim x As String
> x = Me!BED
> y = MsgBox(x, vbInformation)
>
> Dim mySQL As String
> mySQL = "UPDATE TableBED"
> mySQL = mySQL & "SET TableBED.BED_Occupied_ = False"
> mySQL = mySQL & " WHERE TableBed.BED_ = x"
>
> DoCmd.SetWarnings False
> DoCmd.RunSQL mySQL
> DpCmd.SetWarnings True
>
> DoCmd.RunCommand acCmdSelectRecord
> DoCmd.RunCommand acCmdDeleteRecord
>
> Exit_Command27_Click:
> Exit Sub
>
> Err_Command27_Click:
> MsgBox Err.Description
> Resume Exit_Command27_Click
>
> End Sub
>
> Many thanks,
> Max


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
One form to amend 3 tables kealaz Microsoft Access 2 2nd Nov 2009 08:04 PM
Copy all data into one sheet and insert origin data... code amend... harteorama@googlemail.com Microsoft Excel Programming 3 15th Sep 2008 02:54 PM
how do I amend data in linked access tables doctorwho Microsoft Access External Data 2 14th Dec 2007 06:13 PM
Insufficient pemissions to amend Excel files but can amend Word fi =?Utf-8?B?RiBMYXVmcw==?= Microsoft Windows 2000 Security 0 11th Oct 2006 12:28 PM
Database Window - View/Amend Tables and Queries =?Utf-8?B?R29kZGVycw==?= Microsoft Access 0 12th Jan 2005 11:39 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:27 PM.