forms problems please help if you can

ytros

New member
Local time
Yesterday, 22:13
Joined
May 13, 2011
Messages
4
Hi everyone,
I'm a new one. I got a problem with a forms in access + vba. It doesn't work and I can't find out what's wrong with it. Please help if you have a better idea. Many thanks.

Well, I created a forms "Fclient" for searching, adding,.. a record into a table named "Tclient".
In this table " Tclient " i have
ncli int Auto_increment, Primary key
nom Text, nomindex
prenom Text
adresse Text
tel Text
supression yes/no

remarque: I used Access 2000 so .."Option Explicit" is demanded
nomi, teli, prenomi, adressei...are the name of the Input Ab have used in forms "Fclient"


In the Forms "Fclient", in VBA code I wrote :
Code:
Option Compare Database
Option Explicit
Dim mabase As Database
Dim tcli As Recordset
 
Private Sub bajoute_Click()//add a record into a table 'Tclient'
   Set mabase = CurrentDb
   Set tcli = mabase.OpenRecordset("Tclient", dbOpenTable)
   tcli.AddNew
 
   tcli![nom] = Forms!Fclient!nomi
   tcli![prenom] = Forms!Fclient!prenomi
   tcli![adresse] = Forms!Fclient!adressei
   tcli![tel] = Forms!Fclient!teli
   ncli = tcli![nclient]
   tcli.Update
End Sub
 
Private Sub befface_Click() //Erase input data
   Forms!Fclient!nomi = ""
   Forms!Fclient!prenomi = ""
   Forms!Fclient!adressei = ""
   Forms!Fclient!teli = ""
   Forms!Fclient!ncli = ""
   Forms!Fclient![nomi].SetFocus
 
End Sub
 
Private Sub brecher_Click()//search a record in table "Tclient"
   Set mabase = CurrentDb
   Set tcli = mabase.OpenRecordset("Tclient", dbOpenTable)
   tcli.Index = "nomclientindex"
   tcli.Seek "=", Forms!Fclient!nomi
 
If tcli.NoMatch = False Then
   If tcli![supression] = False Then
      Forms!Fclient!nomi = tcli![nom]
      Forms!Fclient!prenomi = tcli![prenom]
      Forms!Fclient!adressei = tcli![adresse]
      Forms!Fclient!teli = tcli![tel]
      Forms!Fclient!ncli = tcli![nclient]
   Else
      MsgBox "ce client n'existe plus"
      Forms!Fclient!nomi = ""
      Forms!Fclient![nomi].SetFocus
   End If
Else
   MsgBox "ce client n'existe pas"
   Forms!Fclient!nomi = ""
   Forms!Fclient![nomi].SetFocus
 
End Sub
 
Last edited by a moderator:
1. Use code tags when posting code (especially large bits of code).

2. You haven't given us enough to go on really. When you say "it doesn't work." What does that mean EXACTLY? We can't see your setup, we can't tell what you're doing, and so you have to be our ears and eyes and tell us in more descriptive terms than "it doesn't work."
 
Oh, and it is amazing how indenting your code can help. I just spotted a missing END IF in there.

Code:
Private Sub brecher_Click()//search a record in table "Tclient"
   Set mabase = CurrentDb
   Set tcli = mabase.OpenRecordset("Tclient", dbOpenTable)
   tcli.Index = "nomclientindex"
   tcli.Seek "=", Forms!Fclient!nomi
 
If tcli.NoMatch = False Then
   If tcli![supression] = False Then
      Forms!Fclient!nomi = tcli![nom]
      Forms!Fclient!prenomi = tcli![prenom]
      Forms!Fclient!adressei = tcli![adresse]
      Forms!Fclient!teli = tcli![tel]
      Forms!Fclient!ncli = tcli![nclient]
   Else
      MsgBox "ce client n'existe plus"
      Forms!Fclient!nomi = ""
      Forms!Fclient![nomi].SetFocus
   End If
Else
   MsgBox "ce client n'existe pas"
   Forms!Fclient!nomi = ""
   Forms!Fclient![nomi].SetFocus
[B][COLOR=red] End If[/COLOR][/B]
End Sub
 
dear Mr Boblarson,
Thank you for your help..yes you're right that's a copy and paste error ..I h've missed End If.
In fact, when i click on the button Add of Form "Fclient" it display a message " The expression On Click you entered as the event property setting produced the following error User-defined type not defined . The expression may not result int he name of a macro the name of a user defined function or Event -Procedure...."
 

Users who are viewing this thread

Back
Top Bottom