View Full Version : Please! 3rd post!


mymy
07-04-2001, 05:59 AM
There is my code. The only thing that I would like to do is to display a field jointed to the same table of the packet_number. Everything is on a subform and I use Access2000. This field that I want to display is not the only one in the table but it's the only one that I want to display in my subform.
Thanks a lot!!

Private Sub packet_number_BeforeUpdate()
Dim condition As String

condition = "[packet_number]='" & Me! [packet_number] & "'"
If DLookup ("[packet_number]", "table_name",condition) <> "" Then
MsgBox "this number exist"
Else
MsgBox "This number doesn't exit"
DoCmd.CancelEvent
End If
End Sub

Jack Cowley
07-04-2001, 06:32 AM
I don't quite understand your question but if you are trying to use DLookup to see if a record is in the table then this code should work for you. I am assuming that packet_number is a number and not text.

Private Sub packet_number_BeforeUpdate(Cancel as Integer)

If Not IsNull(DLookup ("[packet_number]", "table_name","[packet_number]= " & Me! [packet_number])) Then
MsgBox "this number exist"
Else
MsgBox "This number doesn't exit"
Cancel = True
End If
End Sub

If your packet_number is text then use the syntax that you use in your Condition statement. Also the Before Update event normally reads BeforeUpdate(Cancel as Integer). You want to Cancel the update using Cancel.


[This message has been edited by Jack Cowley (edited 07-04-2001).]

mymy
07-04-2001, 06:55 AM
the only thing that I want is to display another field in the subform when the packet_number already exist. I want to take this field in the table (the same then the packet_number) and display it in the subform. I don't know what to add in my code to do it.
the packet_number is a text(5nubmers + 1 letter)
the other is numeric.

Thanks in advance

D-Fresh
07-04-2001, 02:01 PM
just filter the subforms data...

me!SubFormName.Form.Filter = "[Packet_Number]='" & me![packet_Number] & "'"
me!SubFormName.Form.Filteron = true