Re: what is wrong with this code?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Dirk Goldgar (dg_at_NOdataSPAMgnostics.com)
Date: 09/03/04


Date: Fri, 3 Sep 2004 12:09:25 -0400


"hermie" <hermie@coqui.net> wrote in message
news:9tZZc.343$tT5.126@fe61.usenetserver.com
> In the field [ss] on my data entry form I put code in the afterUpdate
> field. The code runs but not update the field in table notas. First
> I get the message: You are about to run an append query that will
> modify data in your table. when I click OK a second message appears
> which says: You are about to append 0 row(s) What should be 1 row
>
> What is wrong with the code?
>
> Private Sub ss_AfterUpdate()
> DoCmd.OpenQuery ("Students_Without_Matching_Notas")
> Run
> DoCmd.Close ("Students_Without_Matching_Notas")
> DoCmd.OpenQuery ("addssnota")
> End Sub
>
> any help is welcome
>
> Herman

1. I don't understand what is the purpose of the line

> Run

As far as I can tell, it isn't going to do anything.

2. This line:

> DoCmd.Close ("Students_Without_Matching_Notas")

should fail, since it doesn't conform to the correct syntax for the
DoCmd.Close method. Have you got "On Error Resume Next" in force
somehow?

3. Does your append query, "addssnota", rely on the value of [ss] being
stored in a table already? If so, that won't have happened yet in the
AfterUpdate event of that control, because the current record won't have
been saved yet. You can force the record to be saved by executing the
line

    RunCommand acCmdSaveRecord

before executing the append query -- presuming that all required fields
have been completed and the record is valid. Or you could run your code
in the *form's* AfterUpdate or AfterInsert event instead.

-- 
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)


Relevant Pages

  • Re: Go to Control with IIf statement
    ... The code doesn't go in the "Form" AfterUpdate event. ... MsgBox "Must fill in Approved Pantone Number", ... Candia Computer Consulting. ... Private Sub Form_AfterUpdate ...
    (microsoft.public.access.formscoding)
  • Re: Add a new record to a third table
    ... Allen Browne - Microsoft MVP. ... >> Private Sub Form_AfterUpdate ... >> Dim strSql As String ... >> literal value, change it to an Append query, switch to SQL ...
    (microsoft.public.access.formscoding)
  • Re: spell checking error
    ... >Private Sub Resolution_AfterUpdate ... >> and BeforeUpdate event procedures. ... >> text box shouldn't have a BeforeUpdate procedure. ... >>>> Try moving the code to the control's AfterUpdate event. ...
    (microsoft.public.access.formscoding)
  • Re: Word equals color
    ... used on the top and bottom of 3x (tab) forms for the same record. ... the typed in information updates and only the first form ... Private Sub ColorClassification ... Then, I would put code in the combo boxes AfterUpdate event, and the forms ...
    (microsoft.public.access.formscoding)
  • Re: Message box when data is entered in a form
    ... Private Sub Form_OnUpdate ... AfterUpdate event for the form (make sure it's the form, ... Doug Steele, Microsoft Access MVP ...
    (microsoft.public.access.forms)