DataBase - Subform updating in error

Asked By KC_Cheer_Coach
13-Nov-09 03:25 PM
I have this written this in ACCESS 2007:

Private Sub USAGE_PERIOD_AfterUpdate()
If DCount("*", "tblImportTracker", "[FileName] = '" & Me![FILENAME] & "' And
[RunNo] = " & Me![RunNo] & " And [UsagePeriod] = " & Me![UsagePeriod] & "") >
0 Then
Cancel = True
Me![txtDuplicatesWarning] = "DUPLICATE"
Else
Me![txtDuplicatesWarning] = "UNIQUE"
[Forms]![frmMain].[Form]![ frmImportTracker subform].Requery
End If
End Sub

FileName is a text field
RunNo is a Long Integer
UsagePeriod is a Long Integer
txtDuplicatesWarning is an unbound field on the parent form that is only
there to let the user know if the entered information is a duplicate or not.

My problem is when duplicate information is entered, tblImportTracker is
updated and the subform reflects this after the db is closed and reopened.
So, now my table has duplicate info in it and it should not. I also get a
run-time error 2448 stating I cannot assign a value to txtDuplicatesWarning
and I do not know why.

Can anyone help?
FrmImportTracker
(1)
TblImportTracker
(1)
BeforeUpdate
(1)
UsagePeriod
(1)
RunNo
(1)
Portugues
(1)
Reflects
(1)
Brasil
(1)
  Jeanette Cunningham replied to KC_Cheer_Coach
14-Nov-09 07:16 PM
Hi KC,
The code you have used, was originally written to be used an the
BeforeUpdate event.
Note the line
Cancel = True

The after update event does not allow you to cancel it, so the cancel = true
will not do anything here.

Move your code to the before update event.

The best place to check for possible duplicates is in the before update
event of the form.
When the form gets to its before update event, you can run some code to
check that all required fields have been filled in before you run the check
for duplicates.

If you check for duplicates in the before update of a control, some of the
other controls needed to check for a duplicate may be still empty.

I recommend that you move the code to the before update event for the form.


--
Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
  KC_Cheer_Coach replied to Jeanette Cunningham
19-Nov-09 10:21 AM
I did what you said and it functions, but not without a lot of headache and
frustration. This is what I mean...

When I enter values that are duplicates, the duplicateswarning field does
not populate until I click all over the form. The "click" is never in the
same spot for it to populate with "Duplicate". So, the user will never know
if the information is a duplicate right away.

When I enter values that are not duplicates, the duplicateswarning field
acts the same way as above. Then, even when it does finally tell me the
information is "Unique", the subform will not update even with a requery. The
only time it will update is if I close Access and reopen it.

Do you have any ideas on what I can do to solve this? I have tried several
different things since and still the same result.

I appreciate your quick response to my question.

KC
  Jeanette Cunningham replied to KC_Cheer_Coach
19-Nov-09 08:03 PM
There is more than problem in this.
Let's do the most important problem first.
1. Subform not updating until you close and reopen access.

The usual reason for this behavior is the relationships between the tables
that the form and subform are based on.
Would you post the names of the tables, their primary keys and foreign keys
and the relationships for the tables
involved in these 2 forms.



Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
  KC_Cheer_Coach replied to Jeanette Cunningham
20-Nov-09 03:07 PM
That could be the problem! I am looking at it right now and there are no
relationships build between these two. Let me mess with it over the weekend
and I will let you know if I still have an issue or not on Monday.

Thanks!
  Davi Rodrigues Chaves replied to KC_Cheer_Coach
23-Nov-09 06:06 PM
- Ol??, lingua portugues brasil , copie o seu documento para o seu propont.

not??cia da mensagem:BE54DEEF-E7E8-45FE-AE5F-789DC50C375B@microsoft.com...
  bill replied to KC_Cheer_Coach
24-Nov-09 11:49 AM

         
Create New Account
help
BeforeUpdate and KeyDown DataBase For a combobox control, I have put some code behind the BeforeUpdate event, and it works very well. . . unless the user enters the value by using a key that I have set the KeyDown event for- -then the BeforeUpdate code does not seem to fire. I tried to add a call to the BeforeUpdate code in the OnExit event, but I cannot seem to make that work, either. If Value set for the field, and it is tabbed thru, accepting the Default Value, the BeforeUpdate code does not fire. How can I get the BeforeUpdate code to fire when a KeyDown event enters a value, or when the Default Value Access Forms Coding Discussions John W. Vinson MVP Microsoft (1) KeyDown event (1) KeyDown (1) BeforeUpdate fires only when the user actually manually updates the field. Either put the same code in your KeyDown event, or call the BeforeUpdate event from your KeyDown code: Call Form.BeforeUpdate(Cancel as Integer) - - John W. Vinson [MVP
Subform dirty state not calling main form's beforeupdate event DataBase In my Access form in the beforeupdate event, I post a question if the user is sure they want to save their different table and noticed if the user makes changes in the subform the main forms beforeupdate event never gets kicked off. Is there a way I can get access to hit the main form's beforeupdate event if changes are made in a subform and the user closes the main form Any thoughts Access Modules DAO Discussions Windows XP (1) AcXP (1) Beforeupdate (1) SubForms have their own BeforeUpdate event. In case you didn't know, a bound MainForm will try to save a Forums.aspx / access-modules / 200804 / 1 keywords: Subform, dirty, state, not, calling, main, form's, beforeupdate, event description: In my Access form in the beforeupdate event, I post a question if the user is sure they want to save their
BeforeUpdate controlla la modifica di un solo campo? DataBase Buond = EC. . . cercando un po' in giro non ho trovato soluzioni :- / E' possibile, nell'evento BeforeUpdate di una maschera, fare un controllo per verificare che alcuni specifici campi della maschera hanno campi) Ad esempio, la maschera contiene le caselle di testo [Nome], [Cognome], [Via], [Citta] Nel BeforeUpdate ci dovrebbe essere qualcosa tipo Se [Via] = E8 stato aggiornato Oppure [Citta] = E8 stato aggiornato esegui questo codice Anticipo che, a causa della struttura della maschera, preferirei non utilizzare il BeforeUpdate del campo, ma quello della maschera (questo perch = E8 il controllo che voglio fare deve se uno o pi = F9 di questi campi = E8 stato modificato. . . se lo facessi sulla BeforeUpdate di ogni casella di testo l'utente si troverebbe decine di messaggi, invece ne vorrei finale) Anche soluzioni alternative che risolvano il problema sono ben accette :) Grazie mille Access Discussions BeforeUpdate (1) OldValue (1) Anticipo (1) Cognome (1) Allora (1) Oppure (1) Grazie (1) Buond (1 Then . . . Vedi anche <F1> per "OldValue". - - HTH Karl * ** ** ** ** Access FAQ: www.donkarl.com / it keywords: BeforeUpdate, controlla, la, modifica, di, un, solo, campo? description: Buond = EC. . . cercando un po' in giro non ho trovato soluzioni :- / E' possibile, nell'evento BeforeUpdate di una maschera, fare un controllo per verificare