Ok, I posted hear earlier and ended up giving a star for some useful tips.. I have another chunk of code playing me up.
The senario is as follows. I have:
forms: frmOutOfStocks
tables: tblOutofStocks
The idea is that I can record when a product is out of stock in my business place. I've included some functionality that creates a "Matchkey" everytime a record is created. this matchkey is made up of three unique factors: Location ID, Date and Product Code.
If someone duplicates entry of an out of stock record, this can be identified from the matchkey. The code below bascially (at run time) will check to see if the current entry already exists.
I have two problems.
1) No matter if i enter a duplicate record or not, the rst.NoMatch always will set to True, indicating a duplicate. I think I have some of the rst.FindLast code wrong.. any help would be appreciated.
2) If I stick some error handling in and put in the Err.Number and Err.Description, it will come up with error 28, Out of Stack space.. why is this and how can I avoid it?
TIA.
The senario is as follows. I have:
forms: frmOutOfStocks
tables: tblOutofStocks
The idea is that I can record when a product is out of stock in my business place. I've included some functionality that creates a "Matchkey" everytime a record is created. this matchkey is made up of three unique factors: Location ID, Date and Product Code.
If someone duplicates entry of an out of stock record, this can be identified from the matchkey. The code below bascially (at run time) will check to see if the current entry already exists.
Code:
Function fDuplicateCheck()
'============================================
'once matchkey has been created, see if any
'other match keys of the same sort exists
'============================================
'declare variables
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("tblOutOfStocks", dbOpenDynaset)
Dim Msg, Style, Title, Response
Msg = "This Out of Stock has previously been recorded. Click OK to delete the existing entry and continue or Cancel to adjust."
Style = vbYesNo + vbCritical + vbDefaultButton2
Title = "Out of Stock Duplicate Entry"
'find records that match the current matchkey
rst.MoveFirst
rst.FindLast "MatchKey = '" & MatchKey & "'"
'actions to take if matchkey already exists / does not exist.
If rst.NoMatch = True Then
'no action necessary - duplicate not found
Else
'duplicate found
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
'get rid of existing duplicate record
rst.Delete
Else
'back to the record without deleting
'no code necessary
End If
End If
rst.Close
End Function
I have two problems.
1) No matter if i enter a duplicate record or not, the rst.NoMatch always will set to True, indicating a duplicate. I think I have some of the rst.FindLast code wrong.. any help would be appreciated.
2) If I stick some error handling in and put in the Err.Number and Err.Description, it will come up with error 28, Out of Stack space.. why is this and how can I avoid it?
TIA.