Abort if "Where" condition not met

  • Thread starter Thread starter Blakey300
  • Start date Start date
B

Blakey300

Hi

I am using access 2007

I have 2 forms which are as follows:

Barcode Search Form (This is just a search form with unbound field)

Competitors (This form holds the data)

I have a macro that opens Competitors form using a where condition
(="[TempEntryID]=" & "'" & [Text0] & "'")

I would like to have it so that if the record is not found the the
competitors form is automatically closed and a messge box appears. then
reverts back to the barcode search form.

In summary I want

open competitors form where ="[TempEntryID]=" & "'" & [Text0] & "'" IF no
record found close Competitors, run message box then open barcode search form

Any help would be greatly appriecated

regards

dave
 
Dave,

Why do you want to open the Competitiors form if there is no matching
record? And then close it again? Any reason to just not open it in the
first place?
 
Because the form is opened automatically when a barcode is scanned. The 1st
form is an unbound search form.

So when a barcode is scanned it will go straight to the relevant record, but
if the record is not scanned i need it to abort the macro

Steve Schapel said:
Dave,

Why do you want to open the Competitiors form if there is no matching
record? And then close it again? Any reason to just not open it in the
first place?

--
Steve Schapel, Microsoft Access MVP


Blakey300 said:
Hi

I am using access 2007

I have 2 forms which are as follows:

Barcode Search Form (This is just a search form with unbound field)

Competitors (This form holds the data)

I have a macro that opens Competitors form using a where condition
(="[TempEntryID]=" & "'" & [Text0] & "'")

I would like to have it so that if the record is not found the the
competitors form is automatically closed and a messge box appears. then
reverts back to the barcode search form.

In summary I want

open competitors form where ="[TempEntryID]=" & "'" & [Text0] & "'" IF no
record found close Competitors, run message box then open barcode search
form

Any help would be greatly appriecated

regards

dave
 
Hi Dave,

Sorry to be dense here. Can you tell us what are the Actions in your macro,
and what event is the macro assigned to i.e. what triggers it? How does the
ID value get written to the Text0 control on the Search Form?

--
Steve Schapel, Microsoft Access MVP


Blakey300 said:
Because the form is opened automatically when a barcode is scanned. The
1st
form is an unbound search form.

So when a barcode is scanned it will go straight to the relevant record,
but
if the record is not scanned i need it to abort the macro

Steve Schapel said:
Dave,

Why do you want to open the Competitiors form if there is no matching
record? And then close it again? Any reason to just not open it in the
first place?

--
Steve Schapel, Microsoft Access MVP


Blakey300 said:
Hi

I am using access 2007

I have 2 forms which are as follows:

Barcode Search Form (This is just a search form with unbound field)

Competitors (This form holds the data)

I have a macro that opens Competitors form using a where condition
(="[TempEntryID]=" & "'" & [Text0] & "'")

I would like to have it so that if the record is not found the the
competitors form is automatically closed and a messge box appears. then
reverts back to the barcode search form.

In summary I want

open competitors form where ="[TempEntryID]=" & "'" & [Text0] & "'" IF
no
record found close Competitors, run message box then open barcode
search
form

Any help would be greatly appriecated

regards

dave
 
Steve

My Macro is as follows:

Open Form Competitors
Where ="[TempEntryID]=" & "'" & [Text0] & "'"
Close Form Barcode Search

The macro is triggered via AfterUpdate of text0 control in the barcode
search form

The Value is entered into text0 via the barcode scanner (the barcode scanner
automatically types the barcode then presses enter which then fires the macro)

Steve Schapel said:
Hi Dave,

Sorry to be dense here. Can you tell us what are the Actions in your macro,
and what event is the macro assigned to i.e. what triggers it? How does the
ID value get written to the Text0 control on the Search Form?

--
Steve Schapel, Microsoft Access MVP


Blakey300 said:
Because the form is opened automatically when a barcode is scanned. The
1st
form is an unbound search form.

So when a barcode is scanned it will go straight to the relevant record,
but
if the record is not scanned i need it to abort the macro

Steve Schapel said:
Dave,

Why do you want to open the Competitiors form if there is no matching
record? And then close it again? Any reason to just not open it in the
first place?

--
Steve Schapel, Microsoft Access MVP


Hi

I am using access 2007

I have 2 forms which are as follows:

Barcode Search Form (This is just a search form with unbound field)

Competitors (This form holds the data)

I have a macro that opens Competitors form using a where condition
(="[TempEntryID]=" & "'" & [Text0] & "'")

I would like to have it so that if the record is not found the the
competitors form is automatically closed and a messge box appears. then
reverts back to the barcode search form.

In summary I want

open competitors form where ="[TempEntryID]=" & "'" & [Text0] & "'" IF
no
record found close Competitors, run message box then open barcode
search
form

Any help would be greatly appriecated

regards

dave
 
Dave,

If it was mine, I would put a Condition for the OpenForm action, along the
lines of this:
DCount("*","NameOfTableCompetitorsFormBasedOn","[TempEntryID]='" & [Text0] &
"'")>0

Then again, I think if it was mine, I think I would dispense with the
Barcode Search form in any case, and use a SetTempVars macro to capture the
output of the barcode scanner, and then go straight to an OpenForm action in
which case the Condition something like:

--
Steve Schapel, Microsoft Access MVP


Blakey300 said:
Steve

My Macro is as follows:

Open Form Competitors
Where ="[TempEntryID]=" & "'" & [Text0] & "'"
Close Form Barcode Search

The macro is triggered via AfterUpdate of text0 control in the barcode
search form

The Value is entered into text0 via the barcode scanner (the barcode
scanner
automatically types the barcode then presses enter which then fires the
macro)

Steve Schapel said:
Hi Dave,

Sorry to be dense here. Can you tell us what are the Actions in your
macro,
and what event is the macro assigned to i.e. what triggers it? How does
the
ID value get written to the Text0 control on the Search Form?

--
Steve Schapel, Microsoft Access MVP


Blakey300 said:
Because the form is opened automatically when a barcode is scanned. The
1st
form is an unbound search form.

So when a barcode is scanned it will go straight to the relevant
record,
but
if the record is not scanned i need it to abort the macro

:

Dave,

Why do you want to open the Competitiors form if there is no matching
record? And then close it again? Any reason to just not open it in
the
first place?

--
Steve Schapel, Microsoft Access MVP


Hi

I am using access 2007

I have 2 forms which are as follows:

Barcode Search Form (This is just a search form with unbound field)

Competitors (This form holds the data)

I have a macro that opens Competitors form using a where condition
(="[TempEntryID]=" & "'" & [Text0] & "'")

I would like to have it so that if the record is not found the the
competitors form is automatically closed and a messge box appears.
then
reverts back to the barcode search form.

In summary I want

open competitors form where ="[TempEntryID]=" & "'" & [Text0] & "'"
IF
no
record found close Competitors, run message box then open barcode
search
form

Any help would be greatly appriecated

regards

dave
 
....
DCount("*","NameOfTableCompetitorsFormBasedOn","[TempEntryID]='" &
[TempVars]![YourVar] & "'")>0

See, that way you reduce it from about 4 steps to 1.
 
Back
Top