Run a Query from a Form

  • Thread starter Thread starter JBad
  • Start date Start date
J

JBad

How can i call / run a query from a form?
Ex:

EmpCode: --- [Find Record]

When the user clicks the Find Record button, the query is run which would
most likely retrieve the correct record.

Is there any other easier way to find a record?

Thanks..
 
It is easy. You can do it with help. If you are talking about a record
within your form, then try adding a combo box in Design View. One of the
options which the Wizard will give you (if your form is based on a table
with a Primary Key) is to find a record in your form.

Are you talking about a record in the form's subform, in another form?

When you add a command button to a form, the Wizard gives you several
options and will do much of the work for you including opening a form of
your choice or Running a Query.

Let us know how you want to do this, give the name of the form/query which
you wish to open and say if EmpCode is text or number

Evi
 
Hi Evi
Thks for the reply but i cudnt fully get the hang of it. Sorry :( . Im a
newbie to Access Programming. Anwyays, here are the details:

EmpNo is a number. I've got a table (for example):

EmpNo as Double
EmpName as Text
DOB as Date
PassportNo as Text
PassportExpDt as Date

Now, I would want the user to enter only the EmpNo in a normal unbound
textbox and upon cliking the "Find Record" button, the snippet should find
that particular record and display the rest of the fields in proper textboxes
or labels (which do u advise?).

For this, should i create a query in the QBE or i can simple write some code
in the OnClick event of the "Find Record" Button?

Thanks a heap...

Evi said:
It is easy. You can do it with help. If you are talking about a record
within your form, then try adding a combo box in Design View. One of the
options which the Wizard will give you (if your form is based on a table
with a Primary Key) is to find a record in your form.

Are you talking about a record in the form's subform, in another form?

When you add a command button to a form, the Wizard gives you several
options and will do much of the work for you including opening a form of
your choice or Running a Query.

Let us know how you want to do this, give the name of the form/query which
you wish to open and say if EmpCode is text or number

Evi


JBad said:
How can i call / run a query from a form?
Ex:

EmpCode: --- [Find Record]

When the user clicks the Find Record button, the query is run which would
most likely retrieve the correct record.

Is there any other easier way to find a record?

Thanks..
 
I don't know what a QBE is.
Coding the On Click event is what you could do - though the wizard will do
the coding for you.

Do you want the info just displayed?

If yes, the easiest way is to create a form (FrmFindEmployee) based on your
Employee table which has just those fields which the user might want to see.

When you've created your text box, use the Properties box on the Other tab
to name it txtFind

Add your button. When the Wizard kicks in, choose Form Operations, Open
Form.
Choose your newly created FrmFindEmployee from the list of forms.

Choose to 'open the form and find Specific Data'

In the left-hand list choose your txtFind box.
In the right hand, choose EmpNo

Does this give the results you wish or have I misunderstood something?

Evi













JBad said:
Hi Evi
Thks for the reply but i cudnt fully get the hang of it. Sorry :( . Im a
newbie to Access Programming. Anwyays, here are the details:

EmpNo is a number. I've got a table (for example):

EmpNo as Double
EmpName as Text
DOB as Date
PassportNo as Text
PassportExpDt as Date

Now, I would want the user to enter only the EmpNo in a normal unbound
textbox and upon cliking the "Find Record" button, the snippet should find
that particular record and display the rest of the fields in proper textboxes
or labels (which do u advise?).

For this, should i create a query in the QBE or i can simple write some code
in the OnClick event of the "Find Record" Button?

Thanks a heap...

Evi said:
It is easy. You can do it with help. If you are talking about a record
within your form, then try adding a combo box in Design View. One of the
options which the Wizard will give you (if your form is based on a table
with a Primary Key) is to find a record in your form.

Are you talking about a record in the form's subform, in another form?

When you add a command button to a form, the Wizard gives you several
options and will do much of the work for you including opening a form of
your choice or Running a Query.

Let us know how you want to do this, give the name of the form/query which
you wish to open and say if EmpCode is text or number

Evi


JBad said:
How can i call / run a query from a form?
Ex:

EmpCode: --- [Find Record]

When the user clicks the Find Record button, the query is run which would
most likely retrieve the correct record.

Is there any other easier way to find a record?

Thanks..
 
Hi Evi

When i get to the part of choosing the matching fields after
'Open Form and Find Specific Data', the left hand side list is empty. It is
not showing the txtFind control. On the right hand side, I've got the field
names in the FrmFindEmployee i want. Why??

Thanks .. JB

Evi said:
I don't know what a QBE is.
Coding the On Click event is what you could do - though the wizard will do
the coding for you.

Do you want the info just displayed?

If yes, the easiest way is to create a form (FrmFindEmployee) based on your
Employee table which has just those fields which the user might want to see.

When you've created your text box, use the Properties box on the Other tab
to name it txtFind

Add your button. When the Wizard kicks in, choose Form Operations, Open
Form.
Choose your newly created FrmFindEmployee from the list of forms.

Choose to 'open the form and find Specific Data'

In the left-hand list choose your txtFind box.
In the right hand, choose EmpNo

Does this give the results you wish or have I misunderstood something?

Evi













JBad said:
Hi Evi
Thks for the reply but i cudnt fully get the hang of it. Sorry :( . Im a
newbie to Access Programming. Anwyays, here are the details:

EmpNo is a number. I've got a table (for example):

EmpNo as Double
EmpName as Text
DOB as Date
PassportNo as Text
PassportExpDt as Date

Now, I would want the user to enter only the EmpNo in a normal unbound
textbox and upon cliking the "Find Record" button, the snippet should find
that particular record and display the rest of the fields in proper textboxes
or labels (which do u advise?).

For this, should i create a query in the QBE or i can simple write some code
in the OnClick event of the "Find Record" Button?

Thanks a heap...

Evi said:
It is easy. You can do it with help. If you are talking about a record
within your form, then try adding a combo box in Design View. One of the
options which the Wizard will give you (if your form is based on a table
with a Primary Key) is to find a record in your form.

Are you talking about a record in the form's subform, in another form?

When you add a command button to a form, the Wizard gives you several
options and will do much of the work for you including opening a form of
your choice or Running a Query.

Let us know how you want to do this, give the name of the form/query which
you wish to open and say if EmpCode is text or number

Evi


How can i call / run a query from a form?
Ex:

EmpCode: --- [Find Record]

When the user clicks the Find Record button, the query is run which would
most likely retrieve the correct record.

Is there any other easier way to find a record?

Thanks..
 
I can't imagine why it isn't working. It normally works even if the button
is in an unbound form.
FrmFindEmployee isn't unbound, is it? It should be based on your Employee
table.

However, we can do this without the Wizard if it wants to be silly!.

Do the button thing again in your launching form but this time just choose
to open the form, FrmFindEmployee.

You should see code that contains lines like these:

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FrmChooseReport"
DoCmd.OpenForm stDocName, , , stLinkCriteria



Just add a line so that it now says

Dim stDocName As String
Dim stLinkCriteria As String

stLinkCriteria = "[EmpNo]=" & Me.txtFind
stDocName = "FrmChooseReport"
DoCmd.OpenForm stDocName, , , stLinkCriteria


Evi

JBad said:
Hi Evi

When i get to the part of choosing the matching fields after
'Open Form and Find Specific Data', the left hand side list is empty. It is
not showing the txtFind control. On the right hand side, I've got the field
names in the FrmFindEmployee i want. Why??

Thanks .. JB

Evi said:
I don't know what a QBE is.
Coding the On Click event is what you could do - though the wizard will do
the coding for you.

Do you want the info just displayed?

If yes, the easiest way is to create a form (FrmFindEmployee) based on your
Employee table which has just those fields which the user might want to see.

When you've created your text box, use the Properties box on the Other tab
to name it txtFind

Add your button. When the Wizard kicks in, choose Form Operations, Open
Form.
Choose your newly created FrmFindEmployee from the list of forms.

Choose to 'open the form and find Specific Data'

In the left-hand list choose your txtFind box.
In the right hand, choose EmpNo

Does this give the results you wish or have I misunderstood something?

Evi













JBad said:
Hi Evi
Thks for the reply but i cudnt fully get the hang of it. Sorry :( . Im a
newbie to Access Programming. Anwyays, here are the details:

EmpNo is a number. I've got a table (for example):

EmpNo as Double
EmpName as Text
DOB as Date
PassportNo as Text
PassportExpDt as Date

Now, I would want the user to enter only the EmpNo in a normal unbound
textbox and upon cliking the "Find Record" button, the snippet should find
that particular record and display the rest of the fields in proper textboxes
or labels (which do u advise?).

For this, should i create a query in the QBE or i can simple write
some
code
in the OnClick event of the "Find Record" Button?

Thanks a heap...

:

It is easy. You can do it with help. If you are talking about a record
within your form, then try adding a combo box in Design View. One
of
the
options which the Wizard will give you (if your form is based on a table
with a Primary Key) is to find a record in your form.

Are you talking about a record in the form's subform, in another form?

When you add a command button to a form, the Wizard gives you several
options and will do much of the work for you including opening a form of
your choice or Running a Query.

Let us know how you want to do this, give the name of the form/query which
you wish to open and say if EmpCode is text or number

Evi


How can i call / run a query from a form?
Ex:

EmpCode: --- [Find Record]

When the user clicks the Find Record button, the query is run
which
would
most likely retrieve the correct record.

Is there any other easier way to find a record?

Thanks..
 
Maybe I'm missing something here, but if you add a command button to the form
you can follow the wizard to make it find records. Then just position the
cursor in any field, click the command button, and find what you need.
 
Back
Top