Hi guys,
I have the following 3 tables & associated keys...
ORDER -> ORDERCARDS -> CARDS
order_id.....order_id...........card_no
client_id......card_no
I have a main form based on ORDER and the subform being the ORDERCARDS, which has a combo box to either select an existing card_no or enter a new one (sourced from table CARDS) - so far straight forward!
The problem I have is that a a card can only be associated with 1 person (i.e. client_id in ORDER), so I have the following filter attached to the combo box so that it only shows card_no's associated with the client_id on the ORDER form...
SELECT CARDS.CARD_NO
FROM ORDER INNER JOIN (CARDS INNER JOIN ORDERCARDS ON CARDS.CARD_NO = ORDERCARDS.CARD_NO) ON ORDER.ORDER_REF = ORDERCARDS.ORDER_REF
WHERE (((ORDER.CLIENT_ID)=[Forms]![ORDER]![ClientIDcombo]));
This does work (as it only shows previous cards issued to that same client), but when trying to enter a new card number the not_in_list event enters the card number in to the CARDS table but I receive an error message "The text you entered isn't an item in the list". The code I have used is...
Private Sub CARD_NO_NotInList(NewData As String, Response As Integer)
Dim strTmp As String
'Get confirmation that this is not just a spelling error.
strTmp = "Add '" & NewData & "' as a new Travelex Card?"
If MsgBox(strTmp, vbYesNo + vbDefaultButton2 + vbQuestion, "Not in list") = vbYes Then
'Append the NewData as a record in the Cards table.
strTmp = "INSERT INTO CARDS ( CARD_NO ) " & _
"SELECT """ & NewData & """ AS CARDS;"
DBEngine(0)(0).Execute strTmp, dbFailOnError
'Notify Access about the new record, so it requeries the combo.
Response = acDataErrAdded
End If
End Sub
If I remove the filter on the combobox it works perfectly, but I can then select a card_no for any client_id (which I wish to avoid).
I know theres a conflict between the filter & the VB code (the card_no is being entered in to the CARDS table, but an entry isnt being created in the ORDERCARDS table, so I can sort-of understand why the information isn't actually in the list as the filter is filtering it out).
Any help would be really appreciated as this is doing my head in.
Cheers
Paul
I have the following 3 tables & associated keys...
ORDER -> ORDERCARDS -> CARDS
order_id.....order_id...........card_no
client_id......card_no
I have a main form based on ORDER and the subform being the ORDERCARDS, which has a combo box to either select an existing card_no or enter a new one (sourced from table CARDS) - so far straight forward!
The problem I have is that a a card can only be associated with 1 person (i.e. client_id in ORDER), so I have the following filter attached to the combo box so that it only shows card_no's associated with the client_id on the ORDER form...
SELECT CARDS.CARD_NO
FROM ORDER INNER JOIN (CARDS INNER JOIN ORDERCARDS ON CARDS.CARD_NO = ORDERCARDS.CARD_NO) ON ORDER.ORDER_REF = ORDERCARDS.ORDER_REF
WHERE (((ORDER.CLIENT_ID)=[Forms]![ORDER]![ClientIDcombo]));
This does work (as it only shows previous cards issued to that same client), but when trying to enter a new card number the not_in_list event enters the card number in to the CARDS table but I receive an error message "The text you entered isn't an item in the list". The code I have used is...
Private Sub CARD_NO_NotInList(NewData As String, Response As Integer)
Dim strTmp As String
'Get confirmation that this is not just a spelling error.
strTmp = "Add '" & NewData & "' as a new Travelex Card?"
If MsgBox(strTmp, vbYesNo + vbDefaultButton2 + vbQuestion, "Not in list") = vbYes Then
'Append the NewData as a record in the Cards table.
strTmp = "INSERT INTO CARDS ( CARD_NO ) " & _
"SELECT """ & NewData & """ AS CARDS;"
DBEngine(0)(0).Execute strTmp, dbFailOnError
'Notify Access about the new record, so it requeries the combo.
Response = acDataErrAdded
End If
End Sub
If I remove the filter on the combobox it works perfectly, but I can then select a card_no for any client_id (which I wish to avoid).
I know theres a conflict between the filter & the VB code (the card_no is being entered in to the CARDS table, but an entry isnt being created in the ORDERCARDS table, so I can sort-of understand why the information isn't actually in the list as the filter is filtering it out).
Any help would be really appreciated as this is doing my head in.
Cheers
Paul