Would somebody mind .......

GizmoT

Registered User.
Local time
Today, 21:45
Joined
May 28, 2003
Messages
86
....snagging this piece of code for me, and telling me why I get the message "The OpenForm action was cancelled"

____________________________________________________

Private Sub AddRecord_Click()
On Error GoTo Err_AddRecord_Click

Dim MyDb As DATABASE
Dim CustTable As Recordset
Dim TrackTable As Recordset
Dim LoanTable As Recordset
Dim IntroTable As Recordset

Dim FilterCriteria As String

Dim stDocName As String
Dim stLinkCriteria As String

Dim CustId As Integer

Dim Code As String
Dim strMsg As String

Code = Left(Me![Surname], 6) & Right(Me![HomeTel], 4) ‘This creates a unique “Identifier”

Set MyDb = DBEngine.Workspaces(0).Databases(0)

If Me![Check] = False Then
Me![Check] = True

Set CustTable = MyDb.OpenRecordset("tblCustomer", DB_OPEN_DYNASET)
FilterCriteria = "[Identifier]='" + Code + "'"
CustTable.Filter = FilterCriteria
Set CustTable = CustTable.OpenRecordset()

If CustTable.EOF = False And CustTable.BOF = False Then

strMsg = MsgBox("These Details appear to be on the system already - Click Yes to View. No to Add Anyway.", vbYesNo)

If strMsg = vbYes Then


stDocName = "frmCustomerDetails"

stLinkCriteria = "[CustomerID]=" & "'" & CustTable![CustomerID] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Else
MsgBox "Click on Update Again to Add Record"

End If

End If


Else

‘Here it adds details to a couple of tables’


End If

Exit_AddRecord_Click:
Exit Sub

Err_AddRecord_Click:
MsgBox Err.Description
Resume Exit_AddRecord_Click

End Sub

____________________________________________________

The code is supposed to check for duplicate entry. If it finds a duplicate it is supposed to open the detail form of the customer so that the user can decide whether to add the record or not. But it keeps getting the message about OpenForm being cancelled. I have deleted some of the code, but I am 99% certain the problem is not there, and wanted to keep this post as simple as possible.

I must be missing something stupid. Thanks
 
Sorry - I should have said that the error message comes at this point:-


If strMsg = vbYes Then


stDocName = "frmCustomerDetails"

stLinkCriteria = "[CustomerID]=" & "'" & CustTable![CustomerID] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria


Thanks
 
I only took five seconds to look at the code but suspect the problem might be here:
stLinkCriteria = "[CustomerID]=" & "'" & CustTable![CustomerID] & "'"
Is [CustomerID] a field that holds text or numeric values?
 
Change the line to:
stLinkCriteria = "[CustomerID]=" & CustTable![CustomerID]
 
Fantastic - Thanks DCX



I said I was missing something stupid - obviously my brain
 
No prob. It's important to know exactly what format your data is in when it is being passed like this. Numbers don't require text delimiters.
 

Users who are viewing this thread

Back
Top Bottom