From: Graeme on
Hi,
I have created by ID field to except text. The ID field is a primary key. With this primary key I have created a listbox. Now, through the listbox I would like to select the ID field and open the form for only that ID. However when I am using the code below, it shows a message saying Syntax error in string in query expression '[ID]=""& Me![ID]'.

Private Sub Command8_Click()
On Error GoTo Err_Command8_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Issue - General"

stLinkCriteria = "[Issue #]=" & Me![List6]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command8_Click:
Exit Sub

Err_Command8_Click:
MsgBox Err.Description
Resume Exit_Command8_Click

End Sub

I would like to know how to fix the code to allow the stLinkCriteria to except a text primary key

---
frmsrcurl: http://msgroups.net/microsoft.public.access/
From: Larry Linson on

"Graeme" <user(a)msgroups.net/> wrote in message
news:%231Jhm8z1KHA.3320(a)TK2MSFTNGP04.phx.gbl...
> Hi,
> I have created by ID field to except text. The ID field is a primary key.
> With this primary key I have created a listbox. Now, through the listbox I
> would like to select the ID field and open the form for only that ID.
> However when I am using the code below, it shows a message saying Syntax
> error in string in query expression '[ID]=""& Me![ID]'.
>
> Private Sub Command8_Click()
> On Error GoTo Err_Command8_Click
>
> Dim stDocName As String
> Dim stLinkCriteria As String
>
> stDocName = "Issue - General"
>
> stLinkCriteria = "[Issue #]=" & Me![List6]
> DoCmd.OpenForm stDocName, , , stLinkCriteria
>
> Exit_Command8_Click:
> Exit Sub
>
> Err_Command8_Click:
> MsgBox Err.Description
> Resume Exit_Command8_Click
>
> End Sub
>
> I would like to know how to fix the code to allow the stLinkCriteria to
> except a text primary key

Try the following:

stLinkCriteria = "[Issue #]=""" & Me![List6] & """"

That's 3 double-quotes after the equal sign and 4 double-quotes after the
last ampersand.

Larry Linson
Microsoft Office Access MVP



From: graeme on
Thank you larry, this has worked. However, I would like an error to occur when the user chooses to select on nothing.
Regards
Graeme

---
frmsrcurl: http://msgroups.net/microsoft.public.access/Listbox-to-open-a-form-primary-key-text