queries on command button

Mrs.Meeker

Registered User.
Local time
Today, 21:48
Joined
Mar 28, 2003
Messages
172
I've been reading about Deleting Records with a Delete Query. I understand that I should create a relationship between tblUser2 and tblQuestionsResults with SurveyNumber and select Enforce Reverential Integrity and Cascade Delete Related Records in the Edit Relationships Box. Because the tables are linked I'm supposed to do that in the database in which they are stored.

This is done.

The purpose is to delete records generated by users who have opened a form and then closed it without filling it out. This creates a survey number in tblUser2, questions in tblQuestionsResults and some flags in tblProjectMaster.

I found some code from Pat Hartman that I want to try but first I need to fix the mess that's already been created. His code is

If IsNull (somefield) or IsNull (someotherfield) Then
msgbox "Record will not be saved. Prease enter required date", vbOKOnly
Cancel = True
End If

I think this is just the ticket but in the meantime...


I read that I cannot delete a field from a record with a delete query that I have to change the data with an update query. It said "If you want to delete data from a field rather than deleting an entire record, you should run an update query to update the field to a zero length string ("") or Null.

So I wrote an update query to remove any flags placed in tblProjectMaster.

Now the part I'm not to sure how to do.

I have created a form which requires the survey number and project number be entered. I would like a command button to run both queries and hopefully they will work.

I read that I could place DoCmd.OpenQuery "YourDeleteQueryName" in the code builder for the button. But I want to run two queries.

Does it matter what order they are run in?
The delete query will delete information from 2 tables.
The update query will delete fields from another table.

Can I run them back to back

DoCmd.OpenQuery "qryDeleteBlankSurvey"
DoCmd.OpenQuery "qryUpdateFlagsTblProjMaster"

Wow, I did this and it worked! Sometimes I get lucky. But now I can't tell that it did anything without going to check the tables and forms and the information is gone.

So I guess my real question would be, what can I do so that I am alerted that the information was successfully deleted?

Rhonda
 
Hi,

try docmd.execute (if you must use docmd - there are alternatives).

The function you want is Msgbox
Its used like this :
[vbcode]
msgbox "Successful! Your records have been deleted",vbokonly+vbinformation,"Record information"
[/vbcode]
The intellisense should give you the options in the vbokonly part :)


Vince
 
That doesn't do me a lot of good if I put bogus information in the fields. I can type XXX and an unused survey number and I still get a success message. I want to know that the correct information was removed. Perhaps I going about this the wrong way.
 

Users who are viewing this thread

Back
Top Bottom