473,396 Members | 1,936 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,396 software developers and data experts.

Making a Form save hidden boxes when Append Query runs?

283 100+
Hello,

First just want to say im going to try and explain this the best I can and hope i dont confuse people :)


What I have is a form to delete a record. Now what I have set the form up to do is pull up the record and then press a button to delete the record. At the same time when the record is deleted I have an Append Query run that makes a copy of the record being deleted. Now I also have a hidden box on the form that captures the users ID so i know who is deleting a record. My problem is this box is not working.

What im having trouble is getting the form to save the one box along with the information that is being appended. I have been trying a lot of save form command combinations but so far no luck. Im just looking for a VB code that will run the append query and at the same time save the hidden box information to the same table at the same time. Also i have a column set up to save the hidden box info to.

Appreciate the help on this!

here is an example of what i have so far...
Expand|Select|Wrap|Line Numbers
  1. Dim stDocName As String
  2.     Dim stDocDel As String
  3.  
  4.     stDocName = "AppendDelRecord"
  5.     DoCmd.OpenQuery stDocName, acNormal, acEdit
  6.     RunCommand acCmdSaveRecord("Text12", "DeletedRecord", "UserDeleted=" & Me.Text12)
  7.  
Jun 29 '10 #1

✓ answered by jimatqsi

I don't know what RunCommand acCmdSaveRecord does, but it seems to me it is your query that should be saving the user ID, not this other command. Your query should have a reference to Forms!formname!Text12 in order to make the append query save the user ID when it saves everything else. But then the query is linked directly to the form and cannot be run except when that form is open. It would be better to do something like this:

Expand|Select|Wrap|Line Numbers
  1. dim dbs as dao.Database
  2. dim rsDeletions as dao.Recordset
  3.  
  4. set dbs = Codedb
  5. set rsDeletions = dbs.Openrecordset("name of table",dbopenDynaset,dbseechanges)
  6. rsDeletions.addnew
  7. rsdeletions!Field1 = me!DataForField1
  8. rsDeletions!Field2 = me!DataForField2
  9.  ... etc for all the fields in the table
  10. rsDeletions!UserID = me!txt12  
  11. rsDeletions.update
  12. rsdeletions.close
  13. set rsdeletions = nothing
  14. set dbs = nothing
  15.  
  16. exit sub  ' also should add error handling
  17.  
And it would be good to choose better names for your data objects. txt12 is not at all descriptive of the content of that object.

Jim




Jim

6 1928
jimatqsi
1,271 Expert 1GB
I don't know what RunCommand acCmdSaveRecord does, but it seems to me it is your query that should be saving the user ID, not this other command. Your query should have a reference to Forms!formname!Text12 in order to make the append query save the user ID when it saves everything else. But then the query is linked directly to the form and cannot be run except when that form is open. It would be better to do something like this:

Expand|Select|Wrap|Line Numbers
  1. dim dbs as dao.Database
  2. dim rsDeletions as dao.Recordset
  3.  
  4. set dbs = Codedb
  5. set rsDeletions = dbs.Openrecordset("name of table",dbopenDynaset,dbseechanges)
  6. rsDeletions.addnew
  7. rsdeletions!Field1 = me!DataForField1
  8. rsDeletions!Field2 = me!DataForField2
  9.  ... etc for all the fields in the table
  10. rsDeletions!UserID = me!txt12  
  11. rsDeletions.update
  12. rsdeletions.close
  13. set rsdeletions = nothing
  14. set dbs = nothing
  15.  
  16. exit sub  ' also should add error handling
  17.  
And it would be good to choose better names for your data objects. txt12 is not at all descriptive of the content of that object.

Jim




Jim
Jun 29 '10 #2
NeoPa
32,556 Expert Mod 16PB
That's a good explanation of what you're doing Slenish, but it's a little short on the detail of the query you're trying to run. I guess it may be a parameter query, but I suspect you'd be better off creating some SQL from scratch, or alternatively, using Jim's idea of a Recordset in your VBA code.

If you want to proceed with a predefined QueryDef, post the SQL you have for it in here and we'll see what we can see for you.
Jun 29 '10 #3
slenish
283 100+
Hi Jim,

Really appreciate your help with this. What you said to try worked great!! A little longer process in a way, but now i dont need the Query i had made to save the information. Thanks a lot!!

Also i am re-naming the boxes :D i just had not gotten to that yet. When im testing stuff i just leave things as no names till I get the bugs worked out.


NeoPa,
Great to hear from you again :D Been a while. The Query I had made was something called an Append Query which is in the drop down query menu.(I read how to make this on the Microsofts Site)

Basically what it did was save a copy of the record before it was deleted. I made a form that i had an Append Query linked to. So what you would do is there was a drop down box you would select a record, then using the cascading box trick it would fill in all the different boxes with the information, then when you would hit the delete record button the Append Query would then make a copy of the information to another table and then prompt you with a msg box to make sure you wanted to delete the record. It worked great just couldnt get the hidden information that was only on the form to save, but by using what Jim suggested it all works great now!

Really apprecaite the help from you both :D
Jun 29 '10 #4
NeoPa
32,556 Expert Mod 16PB
No worries Slenish. It sounds like you have a suitable solution already :)

I've set the Best Answer for you ;)
Jun 30 '10 #5
slenish
283 100+
Whoops!

Thanks NeoPa,
Sorry i forgot to set that as the best answer! In the excitment of getting that to work i forgot, hehe.

Thanks again!
Jul 5 '10 #6
NeoPa
32,556 Expert Mod 16PB
slenish: Whoops!
No big deal. It's done now and took me very little time as I was in here anyway :)
Jul 5 '10 #7

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

Similar topics

2
by: AG | last post by:
I am able to run a query which runs FAst in QA but slow in the application.It takes about 16 m in QA but 1000 ms on the Application.What I wanted to know is why would the query take a long time...
2
by: Paul Wagstaff | last post by:
Hi there I have 2 tables: tblAccuracy & tblClearance Users add new records to tblAccuracy using frmRegister. Under specific conditions I need to append the current record from frmRegister into...
2
by: Ray Holtz | last post by:
I have a form that shows a single record based on a query criteria. When I click a button it is set to use an append query to copy that record to a separate table, then deletes the record from the...
1
by: James Hallam | last post by:
I have a form with a subform. When there are no entries in the subform, I have an append query which makes a default entry in the subform (for what I am doing there needs to be at least one value...
8
by: MLH | last post by:
I would like to modify the following SQL... INSERT INTO tblPmtsRcd (VehicleJobID, PmtAmt) SELECT GetCurrentVehicleJobID() AS MyVehicleJobID, !! AS MyPmtAmt; somehow so that an extra field in...
11
by: kabradley | last post by:
Hello Everyone, So, thanks to nico's help I was finally able to 'finish' our companies access database. For the past week or so though,I have been designing forms that contain a subform and an...
4
by: Scott12345 | last post by:
Hi, here is my situation, I have a DB that tracks machine downtime (30 machines) per day. Several users will update this through the day. I created an append query that creates 30 dummy values and...
3
by: Gerhard | last post by:
Hi I have a combobox on a form which gets it's Row Source from a table. I then use an Append Query to save the selected data in the combobox to a file. Everything works fine. The Combobox's...
8
jinalpatel
by: jinalpatel | last post by:
I have two tables. tblClass and tblWithdrawn. On my main form(bound to tblClass) I have several data entry fields like Date withdrawn, Status (active or withdrawn) Date Classified etc. Also...
16
by: iheartvba | last post by:
Hi, I have a simple append query which takes data from a form and appends it into a table. INSERT INTO tblSmsSent ( MobileNumber, ClientName, TimeSent, AppointmentTime, AppointmentDate )...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.