take a look - what's wrong w this??

I have a project that contains several class modules, all of which work fine. Today I added a new class module and inserted my code and added a hook for it. The code is getting triggered by the SaveCustomer hook when I add a new customer, however I am getting the error message 'attempt to process com object failed, an unknown error occurred.' Which would seem to indicate that something was wrong with the code. So I stripped the code down so pretty much all I had was a msgbox, and I'm still getting the error message. Is this a problem with the hook or with the code that is triggered by the hook? Here's the code that I attempted to run:

Public Function Process(session As Object) As Boolean 'Dim posSession As QSRules.SessionClass Dim posSession As Object Set posSession = session

MsgBox "TEST"

Process = True End Function

Thank you, Kevin

Reply to
kskinne
Loading thread data ...

Save Customer doesn't pass a Session, it passes an Integer which is the Customer.ID...

In your registry settings for this hook, change the Parameter from 1 to 5 (Record ID). In your project, change the Process Function to take an Integer instead of a Session... Public Function Process(customerID as Integer) as boolean

Reply to
Glenn Adams [MVP - Retail Mgmt]

Hi Glenn - I already have the parameter set to 5 for my hook, so I changed my Process Function as you outlined in your reply. Re-compiled and registered, and tried it again but I get the same error message when the hook triggers the code. Any other ideas?

Thank you, Kev> Save Customer doesn't pass a Session, it passes an Integer which is the

Reply to
kskinne

Did you get rid of the line that's trying to use the session variable? That's the only other obvious thing I see...

Reply to
Glenn Adams [MVP - Retail Mgmt]

Glenn, I switched from using Integer to Long as the data type for CustomerID and now it works, thank you very much for your help

Kevin

"Glenn Adams [MVP - Retail Mgmt]" wrote:

Reply to
kskinne

Glenn, my code works now, but I don't know if I'm going to be able to do what I was hoping. I'm trying to prevent the creation of duplicate customer accounts.

What I'm trying to do is trigger this code with the CustomerSave hook, and have the code return a recordset from the DB where the FirstName, LastName, and Address from the customer table matches the FirstName, LastName, and Address of the customer record that the cashier is attempting to add. If the recordset that is returned empty it would continue and write the new customer to the DB. Otherwise it would cancel the save and give the cashier a message. I was trying to use Transaction.Customer.Firstname for example in the WHERE clause of my SQL statement that was pulling the data from the customer table into my RecordSet. But this must not be correct because it is not pulling any data from the customer table even when I try to create a new customer as a duplicate with all the same information as an already existing customer.

Is what I'm attempting to do even possible? Here's what I have for a code so far:

Public Function Process(customerID As Long) As Boolean On Error Resume Next 'Dim posSession As QSRules.SessionClass Dim posSession As Object Set posSession = session With posSession.Transaction glbsqlstr = "SELECT FirstName, LastName, Address FROM Customer WHERE FirstName = " & .Customer.FirstName & " AND LastName = " & .Customer.LastName Set glbRecSet = session.Database.OpenRecordset(glbsqlstr, True) MsgBox glbRecSet("FirstName") End With Process = True End Function

Thanks, kevin

Reply to
kskinne

The "On Error Resume Next" is masking the fact that "session" does not exist.

This still isn't going to work, because SaveCustomer is called AFTER the customer is saved to the database - that's why it can pass you the Customer ID.

You have 2 options:

1) Use a SQL trigger to enforce this rule - big disadvantage - no way to throw a friendly message to the user telling them that the user was not created because they already exist. 2) Disable the "New" and "Copy" buttons on the Customer List and write a more extensive application that takes over the customer creation and selection functions - Launch this app form a Custom POS Button (which can pass a session).
Reply to
Glenn Adams [MVP - Retail Mgmt]

BeanSmart website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.