Small problem!

  • Thread starter smael smael via AccessMonster.com
  • Start date
S

smael smael via AccessMonster.com

I have a form called Annonce_final_modif, and I want it to open up to a
Phone Number that is entered by the user. I have an another form called
Annonce_final in which the user
would type in the Phone Number and it will open up Annonce_final_modif to
that Phone Number. It
doesn’t work perfectly fine, because my problem is that when the user opens
the Annonce_final_modif forms, it removes phone number and It jumps to the
first record. I would instead want it to
continue from the record it is on.

I use the function ‘DoCmd.GoToRecord’

For example: The user enters in ‘0326091245’ in the Annonce_final form and
presses the open button which opens the Annonce_final_modif form on the
phone number ‘0326091245”. When the user opens the form, it goes to first
record.
Maybe the method that I am using is wrong, if anyone has any suggestions
let me know.
 
G

Guest

Try this code on the After Update event of the Phone Number field on the
Annonce_final form

Application.Echo False
DoCmd.OpenForm "Annonce_final_modif"
DoCmd.FindRecord Forms!Annonce_final!TelNo, acEntire, , acSearchAll, ,
acAll, True
DoCmd.Close acForm, "Annonce_final", acSaveNo
Application.Echo True
 
S

smael smael via AccessMonster.com

Hello Dennis,

I'm vey sorry but this code doesn't work. Indeed, when the
Annonce_final_modif form opens, it jumps to the first record.

Thanks you.
 
G

Guest

I copied and pasted this code out of one of my databases where it is working
fine.
The form I am opening is based on a table as its record source and the
Docmd.FindRecord will go to the the correct record for any field in the
underlying recordsource. The application.echo statements are there to stop it
briefly displaying record 1 before jumping to the correct record.
 
S

smael smael via AccessMonster.com

Hello Dennis,
Your code works fine, but now I have add a control. Indeed, if the phone
number exists, I display a MsgBox, who says “The phone number also exists”.
And if it exists, the user goes to the Annonce_final_modif form. With the
new control, the code that you give me doesn’t work. Although I have try
everything, and I find nothing.
If you have a suggestion, let me know.

Here is my code :

Private Sub téléphone_AfterUpdate()

If (DCount("*", "requete_telephone")) > 0 Then

MsgBox ("Le numéro de téléphone que vous avez saisi existe déjà!")

Application.Echo False
DoCmd.OpenForm "TEST2"
DoCmd.FindRecord Forms!TEST1!téléphone, acEntire, , acSearchAll, ,
acAll, True
DoCmd.Close acForm, "TEST1", acSaveNo
Application.Echo True

End If

End Sub
**********************************
And here the code of my query (requete_telephone):

SELECT DISTINCT Annonce.téléphone
FROM Annonce
WHERE (((Annonce.téléphone)=[forms]![Annonce_final]![telephone]));



Thanks you!
 
S

smael smael via AccessMonster.com

thanks you for all Denis!!!

It works perfectly fine!

Bye! :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top