473,395 Members | 2,798 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,395 software developers and data experts.

Updating one record at a time

I am trying to add the first field from Table1 to Table2. Using this record in Table2, I am running a set of queries to get my end result. Once the queries are completed for the first record, I want the queries to run for my next record until EOF. Ofcourse, I want this automated using a command button on a form.
Any ideas ? Any help is appreciated.
Nov 22 '06 #1
20 2217
Killer42
8,435 Expert 8TB
I am trying to add the first field from Table1 to Table2. Using this record in Table2, I am running a set of queries to get my end result. Once the queries are completed for the first record, I want the queries to run for my next record until EOF. Ofcourse, I want this automated using a command button on a form.
Any ideas ? Any help is appreciated.
Can I just clarify something? Did you actually mean the first field, or first record?
Nov 22 '06 #2
its actually the 2nd feild in the first record.

Thanks.
Nov 22 '06 #3
Killer42
8,435 Expert 8TB
its actually the 2nd feild in the first record.
Um... sorry, maybe it's just me, but I'm having trouble understanding the process you're trying to perform.

As best I can work out, when you click a button on your form, you want Access to run a bunch of queries (details not provided) for each record in Table1. And basically, one of those queries will be an action query which will copy (or move?) the record to Table2.

Does this sound about right? If so, is each of these queries supposed to provide output to the user, or perform some update, or what?
Nov 22 '06 #4
Sorry...Let me go into the details.

I want to set up a command button on my form that

1. Writes the first record of Field #2 (Primary Field) from Table #1 to Field #1 in Table#2
2. Using only this one record in Table #2, I want it to run a set of queries, and finally a report is generated (steps already completed)
3. Then I want to delete the records (should have only one) in table#2 by replacing it with the second record from Table #1
4. Rerun the queries and generate reports for each one seperately until EOF in Table #1
Nov 22 '06 #5
MMcCarthy
14,534 Expert Mod 8TB
Sorry...Let me go into the details.

I want to set up a command button on my form that

1. Writes the first record of Field #2 (Primary Field) from Table #1 to Field #1 in Table#2
2. Using only this one record in Table #2, I want it to run a set of queries, and finally a report is generated (steps already completed)
3. Then I want to delete the records (should have only one) in table#2 by replacing it with the second record from Table #1
4. Rerun the queries and generate reports for each one seperately until EOF in Table #1
What is the relationship between table1 and table2.

What do you mean by 'Using only this one record in Table #2, I want it to run a set of queries'. This doesn't make any sense. How can you run a query on one record. What queries are you running. If you posted a sample of the query SQL we might be better able to understand what you are trying to do.

My best guess from what you've said is you actually want to run through the records in table1 and based on the value in the primary key you want to run a report based on some query for each record in the table.

If this is the case you would do it by using recordsets and passing the value in this field as criteria to the report in a loop until all records had been gone through. There is no need for a second table.

If this is what you want we can provide the code for your command button.

Mary
Nov 22 '06 #6
>>>My best guess from what you've said is you actually want to run through the records in table1 and based on the value in the primary key you want to run a report based on some query for each record in the table.

That is correct.

>>>>If this is the case you would do it by using recordsets and passing the value in this field as criteria to the report in a loop until all records had been gone through. There is no need for a second table.

Can you please post the code. Thanks for your help in advance.
Nov 22 '06 #7
MMcCarthy
14,534 Expert Mod 8TB
>>>My best guess from what you've said is you actually want to run through the records in table1 and based on the value in the primary key you want to run a report based on some query for each record in the table.

That is correct.

>>>>If this is the case you would do it by using recordsets and passing the value in this field as criteria to the report in a loop until all records had been gone through. There is no need for a second table.

Can you please post the code. Thanks for your help in advance.
OK in the click event behind your command button (cmdPrint for this example). BTW, make sure the DAO library is selected in the references list (Tools --> References).

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cmdPrint_Click()
  3. Dim db As Database
  4. Dim rs As Recordset
  5. Dim strCriteria As String
  6.  
  7.   Set db = CurrentDb
  8.   Set rs = db.OpenRecordset(TableName) ' The aforementioned Table1
  9.  
  10.   rs.MoveFirst
  11.   Do Until rs.EOF
  12.     strCriteria = "[FieldID]=" & rs![FieldID] ' put the name of the relevant field here, assumes a number datatype
  13.     DoCmd.OpenReport "ReportName", , , strCriteria 'Opens the report
  14.     DoCmd.PrintOut ' Prints the Report
  15.     DoCmd.Close acReport, "ReportName" ' Closes the report
  16.     rs.MoveNext
  17.   Loop
  18.  
  19.   rs.Close
  20.   Set rs = Nothing
  21.   Set db = Nothing
  22.  
  23. End Sub
  24.  
Nov 22 '06 #8
Killer42
8,435 Expert 8TB
...BTW, make sure the DAO library is selected in the references list (Tools --> References).
That's something I don't understand. Why should a program which is running in Access need to reference an external library to use the database? Weird...
Nov 22 '06 #9
MMcCarthy
14,534 Expert Mod 8TB
That's something I don't understand. Why should a program which is running in Access need to reference an external library to use the database? Weird...
It's Access, stuuuupid ;)
Nov 22 '06 #10
It's Access, stuuuupid ;)
Thanks for the help. When I run this with the filter option, where Filter = name of query, I am getting a popo-up message asking me to enter the parameter value.

DoCmd.OpenReport "R001-TEST REPORT", , "Q045-TEST REPORT", strCriteria

Here's my code

[html]
Private Sub Command2_Click()
Dim db As Database
Dim rs As Recordset
Dim strCriteria As String

Set db = CurrentDb
Set rs = db.OpenRecordset("T007-CPT SUMMARY") ' The aforementioned Table1

rs.MoveFirst
Do Until rs.EOF
strCriteria = "[CPT CATALOG NUMBER]=" & rs![CPT CATALOG NUMBER] ' put the name of the relevant field here, assumes a number datatype"


'DoCmd.OpenReport "R002-ORIGINAL COMPONENTS TABLE", , strCriteria, strCriteria
'DoCmd.OpenReport "R003-LOW USAGE FOR REPORT", , , strCriteria
'DoCmd.Close acReport, "R003-LOW USAGE FOR REPORT"
'DoCmd.OpenReport "R004-LESS THAN 10 COMPONENTS FOR REPORT", , , strCriteria
'DoCmd.Close acReport, "R004-LESS THAN 10 COMPONENTS FOR REPORT"
'DoCmd.OpenReport "R005-PREFERRED 2 FOR REPORT", , , strCriteria
'DoCmd.Close acReport, "R005-PREFERRED 2 FOR REPORT"
DoCmd.OpenReport "R001-TEST REPORT", , "Q045-TEST REPORT", strCriteria 'Opens the report
DoCmd.OutputTo acOutputReport, "R001-TEST REPORT", , , NO
' Prints the Report
'DoCmd.Close acReport, "R001-TEST REPORT" ' Closes the report
' DoCmd.OutputTo acOutputReport, "R002-ORIGINAL COMPONENTS TABLE", , , NO
'DoCmd.Close acReport, "R002-ORIGINAL COMPONENTS TABLE"
rs.MoveNext
Loop

rs.Close
Set rs = Nothing
Set db = Nothing

End Sub

[/html]
Nov 22 '06 #11
NeoPa
32,556 Expert Mod 16PB
It might save some time and effort if you posted the message asking for 'the parameter value'.
Nov 22 '06 #12
MMcCarthy
14,534 Expert Mod 8TB
It might save some time and effort if you posted the message asking for 'the parameter value'.
Is [CPT CATALOG NUMBER] a field in the table?

Has [CPT CATALOG NUMBER] got a text or number data type?
Nov 22 '06 #13
Is [CPT CATALOG NUMBER] a field in the table?

Yes

Has [CPT CATALOG NUMBER] got a text or number data type?
Text

Thanks.
Nov 22 '06 #14
NeoPa
32,556 Expert Mod 16PB
It might save some time and effort if you posted the message asking for 'the parameter value'.
If you don't respond to requests for information in your own thread, you can expect fewer experts prepared to respond!
Nov 22 '06 #15
If you don't respond to requests for information in your own thread, you can expect fewer experts prepared to respond!
when I run the code, It just comes up with a dialog box with and says parameter value (ok and cancel are the options).

It also send the file to my printer.
Nov 22 '06 #16
NeoPa
32,556 Expert Mod 16PB
when I run the code, It just comes up with a dialog box with and says parameter value (ok and cancel are the options).

It also send the file to my printer.
And you can't tell us what's in the dialog box message (exactly)?
What I need to know before trawling through your code is exactly what the parameter is that it's complaining about.
I can't search for 'Some Unspecified Parameter Value' :S.
Nov 22 '06 #17
And you can't tell us what's in the dialog box message (exactly)?
What I need to know before trawling through your code is exactly what the parameter is that it's complaining about.
I can't search for 'Some Unspecified Parameter Value' :S.
There is no "error" message as such.
It comes up with a interactive message box, with the catalalog number on the top and requires the user to enter a value in the parameter field.

Thanks.
Nov 22 '06 #18
Killer42
8,435 Expert 8TB
It comes up with a interactive message box, with the catalalog number on the top and requires the user to enter a value in the parameter field.
So the parameter it's asking for is catalog number?

It's just that these "enter parameter" type things often mean that a field name or something has been mis-spelled or used incorrectly, and it's definitely a case where the niggly little details are paramount.
Nov 22 '06 #19
NeoPa
32,556 Expert Mod 16PB
There is no "error" message as such.
It comes up with a interactive message box, with the catalalog number on the top and requires the user to enter a value in the parameter field.

Thanks.
Never mind :(.
Nov 22 '06 #20
MMcCarthy
14,534 Expert Mod 8TB
Sorry for the delay, I had to go out ...

Replace

strCriteria = "[CPT CATALOG NUMBER]=" & rs![CPT CATALOG NUMBER]

with

strCriteria = "[CPT CATALOG NUMBER]='" & rs![CPT CATALOG NUMBER] & "'"

and it should work fine. For passing text values you always have to surround with single quotes.

Mary
Nov 22 '06 #21

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

Similar topics

11
by: Jason | last post by:
Let's say I have an html form with 20 or 30 fields in it. The form submits the fields via POST to a php page which updates a table in a database with the $_POST vars. Which makes more sense? ...
1
by: Roy Adams | last post by:
Hi everyone I'm trying to build a shopping cart app using a db the part I'm stuck on is the fact that, if someone adds a product that they have previously added to the cart. I've got it set up to...
1
by: Chris Jackson | last post by:
I'm a novice Access user and am not sure how to solve the following problem. Any help with the following would be greatly appreciated! I have two tables with identical structures, the first holds...
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...
4
by: Darrel | last post by:
I'm creating a table that contains multiple records pulled out of the database. I'm building the table myself and passing it to the page since the table needs to be fairly customized (ie, a...
5
by: junglist | last post by:
Hi guys, I've been trying to implement an editable datagrid and i have been succesful up to the point where i can update my datagrid row by row. However what used to happen was that once i updated...
4
by: Winshent | last post by:
I am having problems with adding items to my shopping cart. The problem occures when adding items that already exists in the cart. When a user adds to cart, they are automatically redirected to...
34
by: Jeff | last post by:
For years I have been using VBA extensively for updating data to tables after processing. By this I mean if I had to do some intensive processing that resulted in data in temp tables, I would have...
5
by: JimmyKoolPantz | last post by:
Situation: I am writing a program that opens up a data file (file ext .dbf), imports the information into a dataset. The program also, searches through the dataset for key words ("company...
15
by: sara | last post by:
I have a Memo field in a table to hold notes from a conversation a social worker has had with a client (this is for a non-profit). If the user needs to update the memo field, I need to find the...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.