Open Form for Record using Autonumber (1 Viewer)

Aimn_4U

Registered User.
Local time
Tomorrow, 02:37
Joined
May 14, 2019
Messages
33
Hi All,

I have been using a the below code on double click to open a form to a specific record:

Private Sub Internal_Unit_Code_DblClick(Cancel As Integer)
DoCmd.OpenForm "AdminPrecedentDetails", , , "[External Unit Code] = '" & Me.External_Unit_Code & "'"
End Sub


This was working fine, however I now have duplicate External Unit Codes so this code will no longer work.
I would like to change the code to look at the field "UnitEquivalence_ID" However I keep getting the following error when I change the code:

Run-Time error '3464':
Data type mismatch in criteria expression


The UnitEquivalence_ID field is an autonumber, would this be causing the error ?

If so is there a different code that can be used ?

Any help would be greatly appreciated.
 

June7

AWF VIP
Local time
Today, 10:37
Joined
Mar 9, 2014
Messages
5,488
Remove the apostrophes. They are for text field parameters, not number.

Date/time type field would require # character.
 

Gasman

Enthusiastic Amateur
Local time
Today, 19:37
Joined
Sep 21, 2011
Messages
14,363
You use single quotes (generally) for text, # for dates and nothing for numerics.

Code:
Private Sub Internal_Unit_Code_DblClick(Cancel As Integer)
DoCmd.OpenForm "AdminPrecedentDetails", , , "[External Unit Code] = " & Me.External_Unit_Code
End Sub

HTH
 

Users who are viewing this thread

Top Bottom