Creating a key on the input form

S

SharonInGa

The selection of one of these fields creates the key field. This field
inputs into a table with a mahy to many relationship. A customer may have a
PO# or a BOL# or both. A PO# takes priority over a BOL#. The process works
great if you are in the record only once. However, an error message appears
saying that there is a problem with the field relationship if you go back
into the record for whatever reason. What event should this code go in or
what can I do differently?

fieldOne, fieldTwo, BOL#, POL#, (Invisible) KeyField


Private Sub PO__LostFocus()
If Me.BOL_ > 1 Then
Me.MerchandisePO_ = Me.BOL_
Else
End If

If Me.PO_ > 1 Then
Me.MerchandisePO_ = Me.PO_
End If

End Sub
 
M

Marshall Barton

SharonInGa said:
The selection of one of these fields creates the key field. This field
inputs into a table with a mahy to many relationship. A customer may have a
PO# or a BOL# or both. A PO# takes priority over a BOL#. The process works
great if you are in the record only once. However, an error message appears
saying that there is a problem with the field relationship if you go back
into the record for whatever reason. What event should this code go in or
what can I do differently?

fieldOne, fieldTwo, BOL#, POL#, (Invisible) KeyField


Private Sub PO__LostFocus()
If Me.BOL_ > 1 Then
Me.MerchandisePO_ = Me.BOL_
Else
End If

If Me.PO_ > 1 Then
Me.MerchandisePO_ = Me.PO_
End If

End Sub


You can use the form's BeforeInset event to do this kind of
thing. The BeforeInsert event only fires when you start to
create a new record.

I don't know why your fields are named PO# and you are using
PO_ in the procedure. A good practice is to **never** use
spaces or other funky characters in names, even if you like
using aquare brackets around names.

In any case, your code could be a little shorter:

If Me.BOL_ > 1 Then
Me.MerchandisePO_ = Me.BOL_
ElseIf Me.PO_ > 1 Then
Me.MerchandisePO_ = Me.PO_
End If
 

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