Button for Search and GoTo

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

Guest

I have a very basic two form database and the main form is only an opening
page that is mainly for looks and has a section to enter a rego number to
look up a vehicle that is on another form. I would like the person making
the enquiry to be able to merely enter the rego number and press enter, if
the database has that exact rego number it will goto and open the other form
and display that information. If the exact vehicle rego is not on the
database then i would like it to open 'add' option to add that vehicle to the
database. I need this process to be as simple as possible for the person
making the inquiry. Thank you
 
Use the AfterUpdate event procedure of the text box to open the form,
filtered to that number.

This example assumes:
- your unbound text box is named FindRego;
- the form to open is named Form2;
- the field to match is name Rego, and is a Text type field.

Private Sub FindRego_AfterUpdate
Dim strWhere As String
If Not IsNull(Me.FindRego) Then
strWhere = "[Rego] = """ & Me.FindRego & """"
DoCmd.OpenForm "Form2", WhereCondition:=strWhere
End If
End Sub
 
Tash,
I use a combo box (ex. cboFindRego) for this purpose. The user can hand
enter normally, but the combo (based on legitimate Rego numbers) will check
to see if the entry is legitimate as it follows the entry with autocorrect
on.

For matches, on the AfterUpdate event, use the OpenForm [Where] argument
to open the form and find the record.
DoCmd.OpenForm "YourFormName", , , "Rego = Forms!YourFindForm!cboRego"

If a NotInList event occurs, trigger code to bypass the finding, and go
directly to a new record.
DoCmd.OpenForm "YourFormName"
DoCmd.GoToRecord acDataTable, , acNewRec
hth
Al Camp
 
I am very very new at using access and therefore is it possible to get you to
write the script or code step by step and then i could follow that and use
copy and paste the details, i have been trying to figure this out for a while
and this is getting quite confusing

Al Camp said:
Tash,
I use a combo box (ex. cboFindRego) for this purpose. The user can hand
enter normally, but the combo (based on legitimate Rego numbers) will check
to see if the entry is legitimate as it follows the entry with autocorrect
on.

For matches, on the AfterUpdate event, use the OpenForm [Where] argument
to open the form and find the record.
DoCmd.OpenForm "YourFormName", , , "Rego = Forms!YourFindForm!cboRego"

If a NotInList event occurs, trigger code to bypass the finding, and go
directly to a new record.
DoCmd.OpenForm "YourFormName"
DoCmd.GoToRecord acDataTable, , acNewRec
hth
Al Camp

Tash said:
I have a very basic two form database and the main form is only an opening
page that is mainly for looks and has a section to enter a rego number to
look up a vehicle that is on another form. I would like the person making
the enquiry to be able to merely enter the rego number and press enter, if
the database has that exact rego number it will goto and open the other
form
and display that information. If the exact vehicle rego is not on the
database then i would like it to open 'add' option to add that vehicle to
the
database. I need this process to be as simple as possible for the person
making the inquiry. Thank you
 
Actually, the code I posted is the code. I used example names for the
combo, form1, and form2, so you'll have to change those object names to what
you really have for names.

This code goes in the AfterUpdate event procedure, and opens the 2nd form,
and finds the record indicated in the 1st form's cboRego.
DoCmd.OpenForm "YourFormName", , , "Rego = Forms!YourFindForm!cboRego"

If you enter a non existing Rego number into cboRego, this code... placed in
the combo box NotInList event, the 2nd form will open right to a NEW record.
DoCmd.OpenForm "YourFormName"
DoCmd.GoToRecord acDataTable, , acNewRec

hth
Al Camp


Tash said:
I am very very new at using access and therefore is it possible to get you
to
write the script or code step by step and then i could follow that and use
copy and paste the details, i have been trying to figure this out for a
while
and this is getting quite confusing

Al Camp said:
Tash,
I use a combo box (ex. cboFindRego) for this purpose. The user can
hand
enter normally, but the combo (based on legitimate Rego numbers) will
check
to see if the entry is legitimate as it follows the entry with
autocorrect
on.

For matches, on the AfterUpdate event, use the OpenForm [Where]
argument
to open the form and find the record.
DoCmd.OpenForm "YourFormName", , , "Rego = Forms!YourFindForm!cboRego"

If a NotInList event occurs, trigger code to bypass the finding, and
go
directly to a new record.
DoCmd.OpenForm "YourFormName"
DoCmd.GoToRecord acDataTable, , acNewRec
hth
Al Camp

Tash said:
I have a very basic two form database and the main form is only an
opening
page that is mainly for looks and has a section to enter a rego number
to
look up a vehicle that is on another form. I would like the person
making
the enquiry to be able to merely enter the rego number and press enter,
if
the database has that exact rego number it will goto and open the other
form
and display that information. If the exact vehicle rego is not on the
database then i would like it to open 'add' option to add that vehicle
to
the
database. I need this process to be as simple as possible for the
person
making the inquiry. Thank you
 
Thank you so very much for your time and help

Al Camp said:
Actually, the code I posted is the code. I used example names for the
combo, form1, and form2, so you'll have to change those object names to what
you really have for names.

This code goes in the AfterUpdate event procedure, and opens the 2nd form,
and finds the record indicated in the 1st form's cboRego.
DoCmd.OpenForm "YourFormName", , , "Rego = Forms!YourFindForm!cboRego"

If you enter a non existing Rego number into cboRego, this code... placed in
the combo box NotInList event, the 2nd form will open right to a NEW record.
DoCmd.OpenForm "YourFormName"
DoCmd.GoToRecord acDataTable, , acNewRec

hth
Al Camp


Tash said:
I am very very new at using access and therefore is it possible to get you
to
write the script or code step by step and then i could follow that and use
copy and paste the details, i have been trying to figure this out for a
while
and this is getting quite confusing

Al Camp said:
Tash,
I use a combo box (ex. cboFindRego) for this purpose. The user can
hand
enter normally, but the combo (based on legitimate Rego numbers) will
check
to see if the entry is legitimate as it follows the entry with
autocorrect
on.

For matches, on the AfterUpdate event, use the OpenForm [Where]
argument
to open the form and find the record.
DoCmd.OpenForm "YourFormName", , , "Rego = Forms!YourFindForm!cboRego"

If a NotInList event occurs, trigger code to bypass the finding, and
go
directly to a new record.
DoCmd.OpenForm "YourFormName"
DoCmd.GoToRecord acDataTable, , acNewRec
hth
Al Camp

I have a very basic two form database and the main form is only an
opening
page that is mainly for looks and has a section to enter a rego number
to
look up a vehicle that is on another form. I would like the person
making
the enquiry to be able to merely enter the rego number and press enter,
if
the database has that exact rego number it will goto and open the other
form
and display that information. If the exact vehicle rego is not on the
database then i would like it to open 'add' option to add that vehicle
to
the
database. I need this process to be as simple as possible for the
person
making the inquiry. Thank you
 
Back
Top