Use "Unbound" textbox as criteria to find record in DB

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I use different lots or unbound textboxes as criteria. (only one single
criteria)
Like use USER ID or USER Name to search DB.

1. When I go to MACRO to Setvalue ([userid]![enabled])
and then GoToControl [userid] how come when the textbox gets it control
and
show in the form as "-1"???

2. The above method only works for one criteria. How about multiple
criteria? Should I go for action query???
 
Relative to question 1.

A value of "-1" typically is a representation of "True". From what
little you show of your instruction it looks like you are setting the
"USER ID" to the value of the enabled property of [userid] (which is
true, since the field is enabled).

I am really not sure what you are trying to accomplish the macro nor
really what you are trying to do. Action query for what?
 
Hi Ron:

I use a form with two unbound (one combo box) other textbox as the searching
criteria to display the record that user will like to find.
(one userid for Combo, other user name for textbox)

In the form, I use a command button to open a Macro.
If the user tries to use userid. Then the macro will execute "setvalue"(for
that combo box user id) first and then GotoControl. Since the combo box get
the value from table, before the user scrool down, the default value appears
in the combo box is -1. How can I overcome this question???

Also if the user want to use both filed for example, User Last Name or
ZIPcode as searching criteria, how to write it in the form???

Thanks
 
It seems that you are doing something in reverse order. Doesn't the
combo box have a "record source"? As a combo box with a source it
already has a value when they have selected an entry. The very presence
of the record source will give the combo box the potential of having a
value - there is no need to set anything into the combobox. The
instruction you quoted in the first posting would seem to be completely
unnecessary and counterproductive.

As to the second question, you need to have three queries defined to be
used as record source.
1) using userid
2) using zip
3) using userid and zip

something like:
if not isnull(me.combo) and not isnull(txtfield) then
load and requery 3 as below
elseif not isnull(me.combo) then
load and requery 1 as below
elseif not isnull(me.txtfield) then
load and requery 2 as below
else
msgbox ("No criteria has been supplied.")
me.combo.setfocus
endif

the code would be something like this:
me.[subform name].recordsource = "the proper query name"
me.[subform name].requery

Ron
 
Hi.

The combo box do have record source (ex: from userid filed in table).

I try different "expression" in GotoControl in Macro. When I set to no, it
shows 0
when I sent to yes, it shows -1. Is any way to get rid of it???
 
Sorry. About the previous post.

In Macro's action, it should be SetValue instead of GotoControl.
In the filed of Setvalue, should I leave expression field blank???
 
I need to see exactly what you are doing in this macro, because the
what you are saying doesn't make sense. What I am saying is that I
cannot think of a reason right now why you need to go to the macro or
any macro.
 
I went back and tried to figure out what you were trying to say on your
first post, and I think I know what part of the problem may be.

SETVALUE that comes up as part of the dropdown in the macros means to
"Replace the value that is in there with something derived from the
expression". It does not mean freeze the value or anything like that.
Also you would not want to disable the field because if they made a
mistake and try to go back and change it they would NOT be able to do
so.

If someone is sitting in a dropdown box and selects a value from the
list, that value is what you will have as a value for that field
whenever you reference the field name. If someone selects a value, you
don't want to replace it with something else. Just leave it as it is
and reference the fieldname when you want to use its value.

If you are on a form and want to go to any other
control/field/button/etc. on that form you do not need to run a macro
to move the focus to that other item. One way is to simply change the
Tab order of the controls/fields on that form so that when the person
hits the tab key they will go there. If you have other reasons to skip
a couple of controls/fields then instead of executing a macro simply
say: me.otherfieldname.setfocus
That will move the cursor to that field.
 
Back
Top