Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can you erase a line of data without opening the table? 2

Status
Not open for further replies.

billquga

Technical User
Aug 23, 2001
19
US
Hello All. I have a line of data in a table that I delete after each use. I enter the data, print a report, then clear the data from the table. is there anyway to do this by either running a macro or module? i would really like to enter the data in a form, print the report from the same form, then erase the data to start over. Any help would be apreciated
 

I can think of these ways.[ol][li]Create a delete query and

Open the query in code with the DoCmd.OpenQuery Method.
OR

Open the query in a macro with the OpenQuery Action.

[li]Use the DoCmd.RunSQL Method to run a SQL statement from VB code.

[li]Use the RunSQL Action in a macro to run the SQL statement.[/ol] Terry L. Broadbent
faq183-874 contains some tips and ideas for posting questions in these forums. Please review it and comment if you have time.
NOTE: Reference to the FAQ is part of my signature and is not directed at any individual.
 
Another way, similar to the one mentioned above would be to do to this. I assume that you only ever have 1 record in the table, create a report, then want this record deleting. On the command button that is used to print the report:

sub printRecord_Click()
dim db as database
dim sSQL as String

' Code here to open and print report

set db = currentdb
sSQL = "Delete * from Table"
db.execute sSQL

set db = nothing

end sub

I hope this makes sense. Using this code assumes that you have a reference to DAO 3.6

Nick
 
Terry, Nick, thank you very much. All the ways mentioned above work perfectly. Thanks Again!
 
Why are you using a table at all? Reference your (unbound) form fields in your report, in place of those table fields and you don't have to save that line of data to begin with. If you want to reuse the form right away, you may want to clear the fields in place of running that delete query.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top