Open form "Client Details" by clicking "CientName" txtBox

M

Mishanya

I have a form (based on query) wich presents ClientName from tblClientDetails.
I want to program a DblClick event, so the user can doubl-click the
ClientName and open frmClientDetails.
So far I have this:

Private Sub ClientName_DblClick(Cancel As Integer)
On Error GoTo Err_ClientName_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmClientDetails"

stLinkCriteria = "[ClientName]=" & "'" & Me![ClientName] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_ClientName_Click:
Exit Sub

Err_ClientName_Click:
MsgBox Err.Description
Resume Exit_ClientName_Click

End Sub

This routine opens the frmClientDetails filtered for all the clients with
matching name.
What should I add to make this procedure open the frmClientDetails for
specific ClientID? I don't want to have CientID txtBox in my form (at least -
not visible), so adding such a txtbox and setting the Click event on it is
not an option. So, probably, I have to trick somehow the criteria line:
stLinkCriteria = "[ClientName]=" & "'" & Me![ClientName] & "'"
so it will check the ClientID field from the query wich the form is based on?
 
B

Beetle

ClientID does not need to be a control on your form, it only needs
to be a field in the recordsource for you to be able to reference it.
Add ClientID to your query (if it's not already there) and modify your
code like;

Private Sub ClientName_DblClick(Cancel As Integer)
On Error GoTo Err_ClientName_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmClientDetails"

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

Exit_ClientName_Click:
Exit Sub

Err_ClientName_Click:
MsgBox Err.Description
Resume Exit_ClientName_Click

End Sub

I have assumed that your ClientID is a numeric field so I removed the
string delimiters.
 
J

Joan Wild

The ClientID doesn't need to be on the form in order to reference it. As
long as it is in the recordsource....
stLinkCriteria = "[ClientID] = " & Me.ClientID
will do it.
 
M

Mishanya

Great!
That's what I tried to do, but it didn't work untill I removed string
delimiters!
Thank You very much

Beetle said:
ClientID does not need to be a control on your form, it only needs
to be a field in the recordsource for you to be able to reference it.
Add ClientID to your query (if it's not already there) and modify your
code like;

Private Sub ClientName_DblClick(Cancel As Integer)
On Error GoTo Err_ClientName_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmClientDetails"

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

Exit_ClientName_Click:
Exit Sub

Err_ClientName_Click:
MsgBox Err.Description
Resume Exit_ClientName_Click

End Sub

I have assumed that your ClientID is a numeric field so I removed the
string delimiters.

--
_________

Sean Bailey


Mishanya said:
I have a form (based on query) wich presents ClientName from tblClientDetails.
I want to program a DblClick event, so the user can doubl-click the
ClientName and open frmClientDetails.
So far I have this:

Private Sub ClientName_DblClick(Cancel As Integer)
On Error GoTo Err_ClientName_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmClientDetails"

stLinkCriteria = "[ClientName]=" & "'" & Me![ClientName] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_ClientName_Click:
Exit Sub

Err_ClientName_Click:
MsgBox Err.Description
Resume Exit_ClientName_Click

End Sub

This routine opens the frmClientDetails filtered for all the clients with
matching name.
What should I add to make this procedure open the frmClientDetails for
specific ClientID? I don't want to have CientID txtBox in my form (at least -
not visible), so adding such a txtbox and setting the Click event on it is
not an option. So, probably, I have to trick somehow the criteria line:
stLinkCriteria = "[ClientName]=" & "'" & Me![ClientName] & "'"
so it will check the ClientID field from the query wich the form is based on?
 

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