Listbox to open a form (primary key text)

G

Graeme

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_Clic

Dim stDocName As Strin
Dim stLinkCriteria As Strin

stDocName = "Issue - General

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

Exit_Command8_Click
Exit Su

Err_Command8_Click
MsgBox Err.Descriptio
Resume Exit_Command8_Clic

End Su

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

Larry Linson

Graeme said:
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
 
G

graeme

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top