473,378 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Update table from subform default value

I'm using Access to track property assigned to personnel. The problem that I've encountered has to do with marking the property as "Surplus" when it is no longer used.

I have a surplus form (frmSurplus) that has an imbedded subform (frmSurplusSubForm). frmSurplus identifies the group that is disposing of the property, and frmSurplusSubForm is a data sheet view of multiple pieces of property being disposed of.

I would like a control button to pass back new information (date surplussed, condition of property, etc.) to the original property assignment table AND update the person assigned to "SURPLUSSED".

frmSurplus is bound to tblSurplussed, and contains only the information pertaining to the act of disposing of the property. frmSurplusSubForm is bound to the table of property assignments (tblPropertyAssignments) which has all of the specifics about each piece of property, including the assignee.

I know how to update tblPropertyAssignments with data added via frmSurplus/frmSurplusSubForm, but want to also update the name of the person assigned to the property to "SURPLUSSED" without the user having to select "SURPLUSSED" from a list. Any and all suggestions are appreciated!
May 8 '07 #1
10 4426
JConsulting
603 Expert 512MB
I'm using Access to track property assigned to personnel. The problem that I've encountered has to do with marking the property as "Surplus" when it is no longer used.

I have a surplus form (frmSurplus) that has an imbedded subform (frmSurplusSubForm). frmSurplus identifies the group that is disposing of the property, and frmSurplusSubForm is a data sheet view of multiple pieces of property being disposed of.

I would like a control button to pass back new information (date surplussed, condition of property, etc.) to the original property assignment table AND update the person assigned to "SURPLUSSED".

frmSurplus is bound to tblSurplussed, and contains only the information pertaining to the act of disposing of the property. frmSurplusSubForm is bound to the table of property assignments (tblPropertyAssignments) which has all of the specifics about each piece of property, including the assignee.

I know how to update tblPropertyAssignments with data added via frmSurplus/frmSurplusSubForm, but want to also update the name of the person assigned to the property to "SURPLUSSED" without the user having to select "SURPLUSSED" from a list. Any and all suggestions are appreciated!
if there is an event you feel is appropriate, you can run an insert statement to chang the name.

Expand|Select|Wrap|Line Numbers
  1.  
  2. currentdb.execute "Update yourtable set [name] = '" & me.namefield & "';"
  3.  
  4.  
something like that?
J
May 8 '07 #2
if there is an event you feel is appropriate, you can run an insert statement to chang the name.

Expand|Select|Wrap|Line Numbers
  1.  
  2. currentdb.execute "Update yourtable set [name] = '" & me.namefield & "';"
  3.  
  4.  
something like that?
J
Thanks for the quick reply!
I've been hammering on it, but no luck yet. The above code would appear to update the Name field for ALL entries. I would like to update only those records added to the Surplus form (each unique record identified by the property serial number).

This is some code that I've tried that results in "Runtime error 438 - Object doesn't support this property or method".

Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2.  
  3. strSQL = " UPDATE tblPropertyAssignments " & _
  4. "[Name] = '" & [Forms]![frmSurplus]![frmSurplusSubForm].txtName & "'," & _
  5. "[User Name] = '" & [Forms]![frmSurplus]![frmSurplusSubform].txtUserName & "'," & _
  6. "WHERE [SerialNumber] = " & [Forms]![frmSurplus]![frmSurplusSubForm].txtSerialNumber & ";"
  7.  
  8. DoCmd.SetWarnings False
  9. CurrentDb.Execute strSQL, dbFailOnError
  10. DoCmd.SetWarnings True
  11.  
  12. End Sub 
  13.  
May 8 '07 #3
JConsulting
603 Expert 512MB
Thanks for the quick reply!
I've been hammering on it, but no luck yet. The above code would appear to update the Name field for ALL entries. I would like to update only those records added to the Surplus form (each unique record identified by the property serial number).

This is some code that I've tried that results in "Runtime error 438 - Object doesn't support this property or method".

Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2.  
  3. strSQL = " UPDATE tblPropertyAssignments " & _
  4. "[Name] = '" & [Forms]![frmSurplus]![frmSurplusSubForm].txtName & "'," & _
  5. "[User Name] = '" & [Forms]![frmSurplus]![frmSurplusSubform].txtUserName & "'," & _
  6. "WHERE [SerialNumber] = " & [Forms]![frmSurplus]![frmSurplusSubForm].txtSerialNumber & ";"
  7.  
  8. DoCmd.SetWarnings False
  9. CurrentDb.Execute strSQL, dbFailOnError
  10. DoCmd.SetWarnings True
  11.  
  12. End Sub 
  13.  

give this a shot

Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2.  
  3. strSQL = " UPDATE tblPropertyAssignments " & _
  4. "[Name] = '" & [Forms]![frmSurplus].Form.[frmSurplusSubForm].txtName & "'," & _
  5. "[User Name] = '" & [Forms]![frmSurplus].Form.[frmSurplusSubForm].txtUserName & "'," & _
  6. "WHERE [SerialNumber] = " & [Forms]![frmSurplus].Form.[frmSurplusSubForm].txtSerialNumber & ";"
  7.  
  8. DoCmd.SetWarnings False '<---You don't need this or the True part using execute
  9. CurrentDb.Execute strSQL, dbFailOnError
  10. DoCmd.SetWarnings True  '<---you don't need this
  11.  
May 8 '07 #4
JConsulting
603 Expert 512MB
what event are you running this off of?
May 8 '07 #5
what event are you running this off of?
This is from an On Click procedure.

I tried the code, but I get the same error.
May 8 '07 #6
JConsulting
603 Expert 512MB
This is from an On Click procedure.

I tried the code, but I get the same error.
I believe you would want to run this when the record on the subform has been updated right?

So wouldn't that put this code on the subform's After_Update event?

If you do that, you can change the code to reference your fields directly.

ex. me.myfield instead of the form!mainform.subform.form...etc...
J
May 8 '07 #7
JConsulting
603 Expert 512MB
I believe you would want to run this when the record on the subform has been updated right?

So wouldn't that put this code on the subform's After_Update event?

If you do that, you can change the code to reference your fields directly.

ex. me.myfield instead of the form!mainform.subform.form...etc...
J
also, remove the dbFailOnError from your execute statement.
J

you are also missing your SET statement in this

strSQL = " UPDATE tblPropertyAssignments set " & _
"[Name] = '" & [Forms]![frmSurplus].Form.[frmSurplusSubForm].txtName & "'," & _
"[User Name] = '" & [Forms]![frmSurplus].Form.[frmSurplusSubForm].txtUserName & "'," & _
"WHERE [SerialNumber] = " & [Forms]![frmSurplus].Form.[frmSurplusSubForm].txtSerialNumber & ";"
May 8 '07 #8
also, remove the dbFailOnError from your execute statement.
J

you are also missing your SET statement in this

strSQL = " UPDATE tblPropertyAssignments set " & _
"[Name] = '" & [Forms]![frmSurplus].Form.[frmSurplusSubForm].txtName & "'," & _
"[User Name] = '" & [Forms]![frmSurplus].Form.[frmSurplusSubForm].txtUserName & "'," & _
"WHERE [SerialNumber] = " & [Forms]![frmSurplus].Form.[frmSurplusSubForm].txtSerialNumber & ";"
Thank you again for your input. I'll try the changes and post the results.
May 9 '07 #9
Thank you again for your input. I'll try the changes and post the results.
No luck yet in getting the code to work. I've put together an update query that will take care of passing the new value back to the existing record, but have another question. is it posible to simultaneously update multiple records listed on a subform? The subform that I have displays each record in a datasheet view.
May 10 '07 #10
JConsulting
603 Expert 512MB
No luck yet in getting the code to work. I've put together an update query that will take care of passing the new value back to the existing record, but have another question. is it posible to simultaneously update multiple records listed on a subform? The subform that I have displays each record in a datasheet view.
To update multiple records, you just have to create the criteria

example

PK...FK...Name....Color.....City............Day
1.....2......bob.......green....hometown.....tuesd ay
2.....2......sam......white.....Dallas..........mo nday

if you have an update statement like

update Day from yourtable set Day = 'Wednesday' where FK=2

Any record with a FK = 2 will have it's day set to Wednesday.

J
May 10 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: DP | last post by:
hi., i've got 3 tables, customer, film and filmrental. i've got a customer form, with a sub form at the bottom, which is a film rental subform. i've created an update query, which when a...
4
by: sparks | last post by:
I am trying to fix a database that someone did about 4 yrs ago in access97. The main table just contains demographics and is on the main form of the database. It has a subform on a tab that...
1
by: savas_karaduman | last post by:
There is a subform embedded into a Main Form... Subform is standing for entering data into a table... There is a combobox on the Main Form... How Combo Box value can be added into table to which...
2
by: Ron | last post by:
Hi All, Okay, I've got a frmOrders with a subform of sfrmDetails. A frmClient has all the client info, plus a subform of sfrmDefaults that has the client's normal ordering defaults (like set...
0
by: Access Programming only with macros, no code | last post by:
ERROR MESSAGE: Could not update; currently locked by another session on this machine. BACKGROUND I have the following objects: Table1 - HO (which has about 51,000+ records) Table2 -...
11
by: Apple001 | last post by:
I am having trouble using SQL UPDATE statement in VBA. I have: Forms: -"frmClaim": Main form. Data is based on table "claim." It has ClaimID, and other fields. ClaimID is the auto number and...
1
by: MLH | last post by:
If the RecordSource for subform SF on main form MF is a query and I change one of the field values in the subform control from 75 to say - 13 and click on another record, the value in the...
1
beacon
by: beacon | last post by:
Hi everybody, I have an Employee table with the following: Table - Employee -------------------------- ID: AutoNum, PK FName: Text LName: Text Status: Yes/No
0
by: skips84s | last post by:
I have a parent form with four tabbed subforms. On subform x, selecting a value from a combo box should update a few controls on this subform, as well as a control on subform y, all done using...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.