Code error

Tophan

Registered User.
Local time
Today, 05:23
Joined
Mar 27, 2011
Messages
374
I was using the below code in a test database and it was working. But since I have added the information to my active database I am getting this error: "Method or data number not found".

The code is:


Code:
Private Sub InstructionNo_GotFocus()
If Me.cboContractNo = 0 Then
            MsgBox "Contract number must be entered first!", vbOKOnly
            Me.cboContractNo.SetFocus
Else
Me.CVINo = Nz(DMax("[CVINo]", "TBLCVI", "[ContractNo] = " & Me.[cboContractNo]), 0) + 1
End If
End Sub

The error is going straight to the line starting with
Code:
Me.CVINo = Nz(DMax...

I haven't changed any field/control names, table names. Not sure what went wrong between the test and the active database. The only difference is that my test was created in MS Access 2016 but my active database is in MS Access 2010. I typed over/copy and pasted the majority of the info...I didn't try to merge into the existing database.

Can someone please help.
 
Have you tried
debug.print Nz(DMax("[CVINo]", "TBLCVI", "[ContractNo] = " & Me.[cboContractNo]), 0) + 1

This in stages to see what bit it doesn't like?
 
Ok...tried that and didn't get an error but the CVINo is not changing; it is to increase in increments of 1 but it is staying at 0.
 
CVINo isn't set as an autonumber is it?
 
If Trim(Me.cboContractNo & "") = "" Then
MsgBox "Contract number must be entered first!", vbOKOnly
Me.cboContractNo.SetFocus
Else
Me.CVINo = Nz(DMax("[CVINo]", "TBLCVI", "[ContractNo] = " & Me.[cboContractNo]), 0) + 1
End If
 
No...it's just a numerical field that is to automatically create sequential numbering starting at 1 each time a new contract is added.

What I did notice is that I DID change the field name.

The code starts with Private Sub InstructionNo_GotFocus(). But now I checked again, I changed the name from InstructionNo to CVINo. When I tried to correct this by changing it to Private Sub CVINo_GotFocus() I got a different error message (see attached)
 

Attachments

  • Capture.PNG
    Capture.PNG
    9.8 KB · Views: 61
Yes don't do it by manually changing the procedure call. Copy the code you have - go to the design view open the event you want to manage then paste the code back in. Access seems to keep a very tight hold on how the event subs are created.
Manually is not on its list of whose allowed in...
 
I deleted the code, deleted the field, saved, closed, re-opened and added everything again and it is working!

Thank you both for your help
 

Users who are viewing this thread

Back
Top Bottom