code problem

F

Fred

hi... i want this code record fields(name,IPCMref and POTdec),only with value
of fields is not exist in table...the problem is that code record fields
when this
exist in table.
Other problem is the button cancel in the msgbox, I
want this button cancel return to the form without record..but this not
happening.
the code is:

nome.SetFocus
If nome.Text = "" Then
MsgBox "Necessita de preencher todos os campos.", vbInformation
Else
If IPCMref2.Value = "" Then
MsgBox "Necessita de preencher todos os campos.", vbInformation
Else
If POTdec2.Value = "" Then
MsgBox "Necessita de preencher todos os campos.", vbInformation
Else
If Me.[nome] = DLookup("[Nome do Parque]", "[Consulta_parque]") Then
MsgBox "O Parque já se encontra adicionado.", vbInformation
Else
If MsgBox("Deseja adicionar o Parque?", vbQuestion + vbOKCancel) = vbCancel
Then
Cancel = True
Else
If Me.Dirty Then Me.Dirty = False
DoCmd.RunCommand acCmdRecordsGoToNew
DoCmd.Close
DoCmd.OpenForm "input"
DoCmd.Close
DoCmd.OpenForm "apresentacao", acNormal
end if
end if
end if
end if
thanks

Fred
 
J

Jeanette Cunningham

Fred,
with the first problem, there are two possible ways.
One is to set a unique index on the table for the fields - name, IPCMref
and POTdec
If you do have a field called name, I strongly suggest you change it to
AName or BName or similar - name is a reserved word in access and will cause
errors further down the track if you use it for a field name.

If you can't set a unique index for those 3 fields, you can use a DLookup to
check if that record already exists.
If the DLookup shows that record is already in the table, then you amend
your code so that it doesn't add that record again.
Otherwise let the record get added.


Jeanette Cunningham -- Melbourne Victoria Australia
 

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