Hi Peter
So, do you want a general-purpose form to look up a product code, and then
use the product code selected to either find a matching record in the
current form (as in your product maintenance form), or to insert into a
field in a new record (as in an order entry form)?
I suggest you write a jacket function which opens your lookup form in
dialog mode. After the user has found and selected a product, the lookup
form makes itself invisible and the function returns the selected product
code.
Something like this:
Public Function LookupProduct() as Variant
Const FormName = "frmLookupProduct"
If SysCmd(acSysCmdGetObjectState, acForm, FormName) Then
' form is already open - set no selection and show the form
With Forms(FormName)
.SelectedProduct = Null
.Visible = True
End With
Else
DoCmd.OpenForm FormName, WindowMode:=acDialog
End If
' wait till the form is made invisible (or perchance closed)
If SysCmd(acSysCmdGetObjectState, acForm, FormName) Then
LookupProduct = Forms(FormName).SelectedProduct
End If
End Function
In your lookup form, declare a module-level public variable:
Public SelectedProduct as Variant
and when the user selects a product:
SelectedProduct = <the selected product code>
Me.Visible = False
You can then call your function whenever you want to look up a product
code, no matter what the context.
Note that, because you are just hiding the form between lookups and not
closing it, each successive lookup will return to the form as it was for
the last search, with the same selection criteria etc. I imagine this
would be more desirable than closing the form between lookups and
retorting each one form scratch. If not, you can just close the form
after retrieving the value.
--
Good Luck
Graham Mandeno [Access MVP]
Auckland, New Zealand
Peter Kinsman said:
Graham
A typical application handles fish in a cold store. Whether the main
form handles Receipts, Sales or Transfers, the user needs to be able to
select the Product Code, but the information to be pasted into the main
form will differ from one activity to the next.
I hope that clarifies what I am trying to achieve.
Peter
Graham Mandeno said:
Hi Peter
I'm sorry, I might be a bit dense, but I have no idea from your message
what it is you are trying to achieve.
Can you please give some more details about how you want to invoke the
search, what you want to search for, how you want the outcome of the
search presented, and what you mean by "pasting the result of the search
into the original form".
I suspect this may simply be a case of constructing and applying a
filter.
--
Good Luck
Graham Mandeno [Access MVP]
Auckland, New Zealand
I will start by warning that I come from a world of procedural
programming, where problems like this would not occur.
In several applications, it is necessary to search for a Product Code,
which is as difficult as you want to make it - I have recently found
that the Text property of a TextBox in conjunction with its KeyUp event
can be most useful in restricting the records presented in a search.
The problem I have is in pasting the result of the search into the
original form, when, within the same database, several forms can call
the same search form. I have tried to do it using the OpenArgs
property of the search form, but this means that the coding behind the
search form has to be altered each time a new form makes use of it
Does anyone have any suggestions please?
Many thanks
Peter Kinsman