UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> nit on list but no combo help    
 
   
hhh1027
post Aug 15 2009, 10:33 PM
Post#1



Posts: 243
Joined: 22-July 09



I have form that I use for data entry and it is one to many relation when I enter item that is not on the main table I get error "you cannot add or change a record because a related record is required in table 'TblMain'". what I do then I close this and enter the product information in the main table and then return and enter the information. How can I make it when I enter item that is not in main table the entry will be erased and I get warning that says "you have to enter product information first" and it will open the form for product information "FrmProductInfo".
Go to the top of the page
 
theDBguy
post Aug 15 2009, 10:39 PM
Post#2


Access Wiki and Forums Moderator
Posts: 75,521
Joined: 19-June 07
From: SunnySandyEggo


Hi,
Not sure if this will work but might be worth a shot. Try using the Form's OnError event to trap the error for a "no parent record" scenario. If successful, you can then discard the error, show your own message, and open the main form for the user to enter a new record first.
Hope that helps...
Go to the top of the page
 
hhh1027
post Aug 15 2009, 11:28 PM
Post#3



Posts: 243
Joined: 22-July 09



I did this in On error event of the form
DoCmd.OpenForm "FrmProductInof"
and it opens the form and I can add the new product and continue but I'm not sure how I can add the warning message
"This product is not in the list do you want to add" and the open the form. Or how I can add maybe dlookup in the beforeupdate event I'm not sure if this good idea.

Thanks
Edited by: hhh1027 on Sun Aug 16 0:32:52 EDT 2009.
Go to the top of the page
 
polant
post Aug 16 2009, 01:02 AM
Post#4



Posts: 583
Joined: 3-December 07
From: Cyprus


Assuming that you are using a combo with row source tblProducts to enter ProductID, you could use the NotInList event of the combo.

CODE
  
Private Sub cboProductID_NotInList(NewData As String, Response As Integer)
Response = acDataErrContinue ' to supress the standard Access msg
Msgbox "The product entered is not in the list!" vbInformation + vbOKOnly,"Data not found"
'If you want to undo just the combo, use:
Me.cboProductID.Undo
'If you want to undo the entire recond, use:
Me.Undo


NOTE: You need to set the combo's Limit To List property to Yes, in order for the NotInList event to fire.

Hope this helps
Go to the top of the page
 
hhh1027
post Aug 16 2009, 01:10 AM
Post#5



Posts: 243
Joined: 22-July 09



Polant,
I'm not using combo this gets enter by barcode reader.
Go to the top of the page
 
polant
post Aug 16 2009, 01:41 AM
Post#6



Posts: 583
Joined: 3-December 07
From: Cyprus


Ok, no prob. The title of the thread confused me.
Go to the top of the page
 
hhh1027
post Aug 16 2009, 10:46 AM
Post#7



Posts: 243
Joined: 22-July 09



I'm actually scanning the item using barcode reader and based on the barcode the rest of the fields gets updated, but one item is not in the main form I got the error. What I like to do is when this error happens get warning "This product is not in the list do you want to add" and undo the barcode entry and then open the form to add the product automatically. so far I did this in the form's error event.
oCmd.OpenForm "FrmProductInof"
This opens the form but I still need to add the warning message and Undo the barcode entry.
Thanks
Go to the top of the page
 
theDBguy
post Aug 17 2009, 09:57 AM
Post#8


Access Wiki and Forums Moderator
Posts: 75,521
Joined: 19-June 07
From: SunnySandyEggo


Hi,
The Form's Error event will fire with certain application errors, you'll have to determine what the error number is for the situation you want to trap.
So, the first thing you'll need to do is remove the DoCmd.OpenForm code and replace it with:
MsgBox Err.Number
Once you know that number, you can then change the code to something like:
If Err.Number = ErrorNumberForNoParentRecordHere Then
Me.Undo
If MsgBox("That product is not in the list. Do you want to add it?", vbYesNo+vbQuestion, "No Record") = vbYes Then
DoCmd.OpenForm "FrmProductIof",,,,,acDialog
End If
End If
(untested)
Hope that helps...
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    17th June 2019 - 10:56 PM