Open List Items Edit Form to a Specific Record (1 Viewer)

Falcon88

Registered User.
Local time
Today, 08:32
Joined
Nov 4, 2014
Messages
299
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??
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:32
Joined
Oct 29, 2018
Messages
21,536
Is Data Entry = Yes?
 

Falcon88

Registered User.
Local time
Today, 08:32
Joined
Nov 4, 2014
Messages
299
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
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:32
Joined
Oct 29, 2018
Messages
21,536
So, is that what you were expecting to get? CompnyID=1

Are there records where CompnyID=1 exist?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:32
Joined
Oct 29, 2018
Messages
21,536
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]
 

Falcon88

Registered User.
Local time
Today, 08:32
Joined
Nov 4, 2014
Messages
299
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)
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:32
Joined
Oct 29, 2018
Messages
21,536
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:

Pat Hartman

Super Moderator
Staff member
Local time
Today, 01:32
Joined
Feb 19, 2002
Messages
43,474
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

Top Bottom