return error

  • Thread starter Thread starter danny
  • Start date Start date
D

danny

Hey,

I am using a primary key to select records. But i am
tyring to figure out that when i enter an invalid key how
can i get it show an error msg instead of outputting 0
resulsts.

Thanks in advance.

Danny
 
Hi Danny,

You need to provide a bit more information -

How are you selecting records? With a query based form, a query by itself, a
subform?

What code do you currently have?
 
Hey Sandra,

I am selecting records using sql select. heres the code:

SELECT [Test Cases].[GAB/SS#], [Test Cases].[Doc-Date], *
FROM [Test Cases]
WHERE ((([Test Cases].[GAB/SS#])=([Forms]![Final Data
Retrieval]![GabId])))
ORDER BY [Test Cases].[Doc-Date] DESC;

Basically, I have a query based form where i enter the
gabId and if the gabId doesnt match any records i need an
error saying that.

Thanks for the help

Danny

-----Original Message-----
Hi Danny,

You need to provide a bit more information -

How are you selecting records? With a query based form, a query by itself, a
subform?

What code do you currently have?


--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

Hey,

I am using a primary key to select records. But i am
tyring to figure out that when i enter an invalid key how
can i get it show an error msg instead of outputting 0
resulsts.

Thanks in advance.

Danny


.
 
Hi Danny,

This looks like SQL in a saved query. Is the form bound to this query? This
would work:

if me.recordsetclone.eof and me.recordsetclone.bof then
msgbox "There are no matches"
end if


--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

Hey Sandra,

I am selecting records using sql select. heres the code:

SELECT [Test Cases].[GAB/SS#], [Test Cases].[Doc-Date], *
FROM [Test Cases]
WHERE ((([Test Cases].[GAB/SS#])=([Forms]![Final Data
Retrieval]![GabId])))
ORDER BY [Test Cases].[Doc-Date] DESC;

Basically, I have a query based form where i enter the
gabId and if the gabId doesnt match any records i need an
error saying that.

Thanks for the help

Danny

-----Original Message-----
Hi Danny,

You need to provide a bit more information -

How are you selecting records? With a query based form, a query by
itself, a subform?

What code do you currently have?


--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

Hey,

I am using a primary key to select records. But i am
tyring to figure out that when i enter an invalid key how
can i get it show an error msg instead of outputting 0
resulsts.

Thanks in advance.

Danny


.
 
Hey Sandra,

It is sql in a saved query and the form's text box uses it.
Where exactly would i put the code that u gave me?

Thanks,

Danny

-----Original Message-----
Hi Danny,

This looks like SQL in a saved query. Is the form bound to this query? This
would work:

if me.recordsetclone.eof and me.recordsetclone.bof then
msgbox "There are no matches"
end if


--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

Hey Sandra,

I am selecting records using sql select. heres the code:

SELECT [Test Cases].[GAB/SS#], [Test Cases].[Doc-Date], *
FROM [Test Cases]
WHERE ((([Test Cases].[GAB/SS#])=([Forms]![Final Data
Retrieval]![GabId])))
ORDER BY [Test Cases].[Doc-Date] DESC;

Basically, I have a query based form where i enter the
gabId and if the gabId doesnt match any records i need an
error saying that.

Thanks for the help

Danny

-----Original Message-----
Hi Danny,

You need to provide a bit more information -

How are you selecting records? With a query based form, a query by
itself, a subform?

What code do you currently have?


--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


danny wrote:
Hey,

I am using a primary key to select records. But i am
tyring to figure out that when i enter an invalid key how
can i get it show an error msg instead of outputting 0
resulsts.

Thanks in advance.

Danny


.


.
 
You would want to use AfterUpdate event of the textbox. Are you simply
opening a query or using it as a recordsource?

If you are opening a query (docmd.openquery) then you would need to test the
query prior to opening using one of the domain aggregate functions:

If DCount("*", "MyQuery") = 0 Then
MsgBox "No records"
End If


--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

Hey Sandra,

It is sql in a saved query and the form's text box uses it.
Where exactly would i put the code that u gave me?

Thanks,

Danny

-----Original Message-----
Hi Danny,

This looks like SQL in a saved query. Is the form bound to this
query? This would work:

if me.recordsetclone.eof and me.recordsetclone.bof then
msgbox "There are no matches"
end if


--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

Hey Sandra,

I am selecting records using sql select. heres the code:

SELECT [Test Cases].[GAB/SS#], [Test Cases].[Doc-Date], *
FROM [Test Cases]
WHERE ((([Test Cases].[GAB/SS#])=([Forms]![Final Data
Retrieval]![GabId])))
ORDER BY [Test Cases].[Doc-Date] DESC;

Basically, I have a query based form where i enter the
gabId and if the gabId doesnt match any records i need an
error saying that.

Thanks for the help

Danny


-----Original Message-----
Hi Danny,

You need to provide a bit more information -

How are you selecting records? With a query based form, a query by
itself, a subform?

What code do you currently have?


--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


danny wrote:
Hey,

I am using a primary key to select records. But i am
tyring to figure out that when i enter an invalid key how
can i get it show an error msg instead of outputting 0
resulsts.

Thanks in advance.

Danny


.


.
 
Hey, Sandra

Thanks for all your help. I just have a couple more
questions. This is my new code for the event where the
search button is clicked.

Private Sub QuerySearch_Click()
On Error GoTo Err_QuerySearch_Click

Dim stDocName As String

stDocName = "FinalQuery"
DoCmd.OpenQuery stDocName, acNormal, acEdit

If DCount("*", "FinalQuery") = 0 Then
MsgBox "No records"
End If

Exit_QuerySearch_Click:
Exit Sub

Err_QuerySearch_Click:
MsgBox Err.Description
Resume Exit_QuerySearch_Click

End Sub

Here, after it says no records found it still opens up an
empty results query which i don't want.

Secondly, I want the error msg to have the value i
searched for which was not found. so basically something
like "no records for Gab# 12345"

Thanks again,

danny
 
Hi Danny,

No problem - just restructure your logic a bit:

Dim stDocName As String
stDocName = "FinalQuery"

If DCount("*", "FinalQuery") = 0 Then
MsgBox "No records found for Gab#" & me.GabId
else
DoCmd.OpenQuery stDocName, acNormal, acEdit
End If
 
Back
Top