By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,972 Members | 1,134 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,972 IT Pros & Developers. It's quick & easy.

Customer List Selection

P: n/a
I have a form called CustomerLookup. It displays a DataSheet of all
our customers so that someone can quickly and easily view all our
customers.

When someone double clicks on one of the customers, I have some VB
code set up that runs some filters, checks against some queries, and
displays relevant message boxes that ultimately result in a form
coming up that lists all of the orders associates with this customer.

Simple stuff.

The problem is with the double clicking. I want a user to be able to
double click on ANY field - address, name, phone, etc. and have the
relevant orders come up, but it seems like an awful waste of space to
have the FULL VB code copied again and again for each OnDoubleClick
event.

Is there a way to have the VB code written ONCE, and then the
OnDoubleClick event for each field just says something like "GoTo
OrderLookUp"?

I have very little programming experience, so details are
appreciated :)

Thanks!

Mar 20 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a

Have you considered making it a continuous form and adding a command
button on one end? It can still look and behave like a datasheet, but
you could add a button to the 'end of the row' that the user could
click on instead of the row fields.

Mar 20 '07 #2

P: n/a
On Mar 20, 5:36 pm, "storrboy" <storr...@sympatico.cawrote:
Have you considered making it a continuous form and adding a command
button on one end? It can still look and behave like a datasheet, but
you could add a button to the 'end of the row' that the user could
click on instead of the row fields.
Yes, but a datasheet looks so much better.

Mar 21 '07 #3

P: n/a
On Mar 21, 8:05 am, dancol...@gmail.com wrote:
On Mar 20, 5:36 pm, "storrboy" <storr...@sympatico.cawrote:
Have you considered making it a continuous form and adding a command
button on one end? It can still look and behave like a datasheet, but
you could add a button to the 'end of the row' that the user could
click on instead of the row fields.

Yes, but a datasheet looks so much better.

Then I think you'll need to put whatever code it is you have into one
function that can be called in the double-click event of each field.

Mar 21 '07 #4

P: n/a
On Mar 21, 9:25 am, "storrboy" <storr...@sympatico.cawrote:
On Mar 21, 8:05 am, dancol...@gmail.com wrote:
On Mar 20, 5:36 pm, "storrboy" <storr...@sympatico.cawrote:
Have you considered making it a continuous form and adding a command
button on one end? It can still look and behave like a datasheet, but
you could add a button to the 'end of the row' that the user could
click on instead of the row fields.
Yes, but a datasheet looks so much better.

Then I think you'll need to put whatever code it is you have into one
function that can be called in the double-click event of each field.
Right... that's what I'm asking. How do I do that? How do I create ONE
function that can be called from multiple events, rather than just
copy the same function over and over and over again?

Mar 21 '07 #5

P: n/a
On Mar 21, 8:47 am, dancol...@gmail.com wrote:
On Mar 21, 9:25 am, "storrboy" <storr...@sympatico.cawrote:
On Mar 21, 8:05 am, dancol...@gmail.com wrote:
On Mar 20, 5:36 pm, "storrboy" <storr...@sympatico.cawrote:
Have you considered making it a continuous form and adding a command
button on one end? It can still look and behave like a datasheet, but
you could add a button to the 'end of the row' that the user could
click on instead of the row fields.
Yes, but a datasheet looks so much better.
Then I think you'll need to put whatever code it is you have into one
function that can be called in the double-click event of each field.

Right... that's what I'm asking. How do I do that? How do I create ONE
function that can be called from multiple events, rather than just
copy the same function over and over and over again?

Seeing as how you've given no indication what the code...

"..that runs some filters, checks against some queries, and
displays relevant message boxes that ultimately result in a form
coming up that lists all of the orders associates with this customer."

actually looks like or does I can only give you a skeleton example.

Make a function in the form code module

Function MyDoubleClickCode(Argument List) As WhateverItNeedsToReturn
On Error Goto Stoprun

<<insert what you have>>

Exit_Here:
Exit Function

Stoprun:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_Here
End Function
Call from doubleclick event of what ever controls apply.

Private Sub Controlname_DblClick(Cancel As Integer)
MyDoubleClickCode Argument List
End Sub

Mar 21 '07 #6

P: n/a
On Mar 21, 10:04 am, "storrboy" <storr...@sympatico.cawrote:
On Mar 21, 8:47 am, dancol...@gmail.com wrote:
On Mar 21, 9:25 am, "storrboy" <storr...@sympatico.cawrote:
On Mar 21, 8:05 am, dancol...@gmail.com wrote:
On Mar 20, 5:36 pm, "storrboy" <storr...@sympatico.cawrote:
Have you considered making it a continuous form and adding a command
button on one end? It can still look and behave like a datasheet, but
you could add a button to the 'end of the row' that the user could
click on instead of the row fields.
Yes, but a datasheet looks so much better.
Then I think you'll need to put whatever code it is you have into one
function that can be called in the double-click event of each field.
Right... that's what I'm asking. How do I do that? How do I create ONE
function that can be called from multiple events, rather than just
copy the same function over and over and over again?

Seeing as how you've given no indication what the code...

"..that runs some filters, checks against some queries, and
displays relevant message boxes that ultimately result in a form
coming up that lists all of the orders associates with this customer."

actually looks like or does I can only give you a skeleton example.

Make a function in the form code module

Function MyDoubleClickCode(Argument List) As WhateverItNeedsToReturn
On Error Goto Stoprun

<<insert what you have>>

Exit_Here:
Exit Function

Stoprun:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_Here
End Function

Call from doubleclick event of what ever controls apply.

Private Sub Controlname_DblClick(Cancel As Integer)
MyDoubleClickCode Argument List
End Sub
This is the code I want to run. How would I go about doing this?

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Requests"
stLinkCriteria = "[BillCustID]=" & "'" & Me![BillCustID] & "'" & "
and Cancelled = 0 and OrdType = 2 and OrdBatchID -1"
DoCmd.Close
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms!Requests.AllowAdditions = True

If Forms![Requests]![OrdType] <"2" Then
Forms!Requests.AllowAdditions = False
DoCmd.Close
Msg2 = "There are no requests on file for this customer. Better
luck next time, chump. HA HA HA HA!"
Title2 = "No Requests Found"
Style2 = vbMsgBoxSetForeground + vbApplicationModal
Response = MsgBox(Msg2, Style2, Title2)
Else
Forms!Requests.AllowAdditions = False
End If

Mar 21 '07 #7

P: n/a
As long as what you have posted does what it is supposed to do, add
the following to the form module. In the DoubleClick event of each
control that is to run this add 'RowDoubleClick' sub name so that it
looks similar to...

Private Sub Controlname_DblClick(Cancel As Integer)
RowDoubleClick
End Sub

!!! PS Watch for improper line wraps

'-------Code Start --- Add to Form
Module------------------------------------------------------
Sub RowDoubleClick()
On Error Goto Stoprun

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Requests"
stLinkCriteria = "[BillCustID]=" & "'" & Me![BillCustID] & "'" &
" _
and Cancelled = 0 and OrdType = 2 and OrdBatchID -1"
DoCmd.Close
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms!Requests.AllowAdditions = True

If Forms![Requests]![OrdType] <"2" Then
Forms!Requests.AllowAdditions = False
DoCmd.Close
Msg2 = "There are no requests on file for this customer.
Better _
luck next time, chump. HA HA HA HA!"
Title2 = "No Requests Found"
Style2 = vbMsgBoxSetForeground + vbApplicationModal
Response = MsgBox(Msg2, Style2, Title2)
Else
Forms!Requests.AllowAdditions = False
End If

Exit_Here:
Exit Sub

Stoprun:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_Here
End Sub
'--------Code End---------------------------------------------------

Mar 21 '07 #8

P: n/a
On Mar 21, 11:45 am, "storrboy" <storr...@sympatico.cawrote:
As long as what you have posted does what it is supposed to do, add
the following to the form module. In the DoubleClick event of each
control that is to run this add 'RowDoubleClick' sub name so that it
looks similar to...

Private Sub Controlname_DblClick(Cancel As Integer)
RowDoubleClick
End Sub

!!! PS Watch for improper line wraps

'-------Code Start --- Add to Form
Module------------------------------------------------------
Sub RowDoubleClick()
On Error Goto Stoprun

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Requests"
stLinkCriteria = "[BillCustID]=" & "'" & Me![BillCustID] & "'" &
" _
and Cancelled = 0 and OrdType = 2 and OrdBatchID -1"
DoCmd.Close
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms!Requests.AllowAdditions = True

If Forms![Requests]![OrdType] <"2" Then
Forms!Requests.AllowAdditions = False
DoCmd.Close
Msg2 = "There are no requests on file for this customer.
Better _
luck next time, chump. HA HA HA HA!"
Title2 = "No Requests Found"
Style2 = vbMsgBoxSetForeground + vbApplicationModal
Response = MsgBox(Msg2, Style2, Title2)
Else
Forms!Requests.AllowAdditions = False
End If

Exit_Here:
Exit Sub

Stoprun:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_Here
End Sub
'--------Code End---------------------------------------------------
That's exactly what I was looking for. Thanks!!!!!!

Mar 21 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.