Opening a form, showing a specific record based on the selection in a list box (1 Viewer)

shery1995

Member
Local time
Today, 15:40
Joined
May 29, 2010
Messages
71
Hi All,
I have a little issue. I am trying to open a form, showing a specific record based on the selection in a list box. I am using the following code and getting "mismatch" error:

DoCmd.OpenForm "frmClients", , , _
"[tblClient.ClientID]=" & "'" & Me.lstSearch.Column(0) & "'"

The form I am opening is "frmClients", which is opened by double clicking on a list box, named "lstSearch". ClientID is a Autonumber. Anyone have any ideas?

Thanks,
 

Gasman

Enthusiastic Amateur
Local time
Today, 15:40
Joined
Sep 21, 2011
Messages
14,262
No quotes if a number?
Code:
DoCmd.OpenForm "frmClients", , , _
       "[tblClient.ClientID]=" & Me.lstSearch.Column(0)
 

mike60smart

Registered User.
Local time
Today, 15:40
Joined
Aug 6, 2017
Messages
1,904
Hi
Gasman beat me to it

The syntax would be something like this

DoCmd.OpenForm "frmClients", , , "[ClientID]=" & [LstSearch].Column(0)
 

shery1995

Member
Local time
Today, 15:40
Joined
May 29, 2010
Messages
71
No quotes if a number?
Code:
DoCmd.OpenForm "frmClients", , , _
       "[tblClient.ClientID]=" & Me.lstSearch.Column(0)
Thank you for your reply it opens up the form but shows no record at all.
 

shery1995

Member
Local time
Today, 15:40
Joined
May 29, 2010
Messages
71
Hi
Gasman beat me to it

The syntax would be something like this

DoCmd.OpenForm "frmClients", , , "[ClientID]=" & [LstSearch].Column(0)
Thank you for your reply it opens up the form but shows no record at all.
 

mike60smart

Registered User.
Local time
Today, 15:40
Joined
Aug 6, 2017
Messages
1,904
In Design View of the Form make sure that on The Data Tab the Data Entry is set to NO
 

mike60smart

Registered User.
Local time
Today, 15:40
Joined
Aug 6, 2017
Messages
1,904
Can you upload a zipped copy of the database?
 

mike60smart

Registered User.
Local time
Today, 15:40
Joined
Aug 6, 2017
Messages
1,904
Try this method


Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmClients"

stLinkCriteria = "[ClientID]=" & Me![LstSearch]
DoCmd.OpenForm stDocName, , , stLinkCriteria
 

Gasman

Enthusiastic Amateur
Local time
Today, 15:40
Joined
Sep 21, 2011
Messages
14,262
Try this method


Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmClients"

stLinkCriteria = "[ClientID]=" & Me![LstSearch]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Add Debug.Print strLinkCriteria first before trying to open the form and post back what that displays.
 

Micron

AWF VIP
Local time
Today, 10:40
Joined
Oct 20, 2018
Messages
3,478
Plus that column does not appear to be used if you Google 'Open form from listbox'?
If the listbox is unbound and you don't use the Column property, the result will be Null. We don't know if the listbox is bound or not. If using the column property provides a result - e.g. in the immediate window type ?forms!NameOfFormHere.ListboxNameHere.Column(0) and hit enter. If the expected value is correct yet produces no records, something else is at play:

- there are no records using that value as a filter (examine or test via query to be sure)
- form Open or Load code is screwing it up
- the field linked to the column value is a multi value field
- ?
 

shery1995

Member
Local time
Today, 15:40
Joined
May 29, 2010
Messages
71
In Design View of the Form make sure that on The Data Tab the Data Entry is set to NO
Thank you so much it's working fine now, it was me who unchecked the ClientID in row source that is why it was not working. Many thanks again
 

Users who are viewing this thread

Top Bottom