Open List Items Edit Form to a Specific Record

Falcon88

Registered User.
Local time
Today, 04:12
Joined
Nov 4, 2014
Messages
306
hi to all

i use this code but open form with a new record :
Code:
Private Sub Form_Load()
Dim MyFilter As String
If CurrentProject.AllForms("MainFrm").IsLoaded Then
MyFilter = "Forms![MainFrm]![InsurCmpName]= " & Me.CompnyID
Me.Filter = MyFilter
Me.FilterOn = True
End If
End Sub
but its go to new record ......
Where is the problem in the code??
 
Is Data Entry = Yes?
 
i do like :

Code:
Dim MyFilter As String
If CurrentProject.AllForms("MainFrm").IsLoaded Then
MyFilter = "Forms![MainFrm]![InsurCmpName]= " & Me.CompnyID
Debug.Print MyFilter
Me.Filter = MyFilter
Me.FilterOn = True
End If

it gives me :
Code:
Forms![MainFrm]![InsurCmpName]= 1
 
So, is that what you were expecting to get? CompnyID=1

Are there records where CompnyID=1 exist?
 
i do like :

Code:
Dim MyFilter As String
If CurrentProject.AllForms("MainFrm").IsLoaded Then
MyFilter = "Forms![MainFrm]![InsurCmpName]= " & Me.CompnyID
Debug.Print MyFilter
Me.Filter = MyFilter
Me.FilterOn = True
End If

it gives me :
Code:
Forms![MainFrm]![InsurCmpName]= 1
Oh wait, what happens if you swap the two?
Code:
MyFilter = "CompnyID=" & Forms![MainFrm]![InsurCmpName]
 
Oh wait, what happens if you swap the two?
Code:
MyFilter = "CompnyID=" & Forms![MainFrm]![InsurCmpName]
thanks it solved .

but what if MainFrm on new record and InsurCmpName is null ?

( err 3075)
 
thanks it solved .

but what if MainFrm on new record and InsurCmpName is null ?

( err 3075)
Try changing it to this then.
Code:
MyFilter = "CompnyID=" & Nz(Forms![MainFrm]![InsurCmpName],0)
 
Last edited:
I doubt this is the correct solution. Normally, we would use the Where argument of the OpenForm method to open a form to a specific record. No extra code is required.

What, exactly, are you trying to do?
 

Users who are viewing this thread

Back
Top Bottom