code for not find record

  • Thread starter laveshhp via AccessMonster.com
  • Start date
L

laveshhp via AccessMonster.com

Hi!
i have search form and i did code for null value for date but i also need
a code for if record didn't match with date retrun with message " 0 record
found"

thanks
lavesh
 
L

laveshhp via AccessMonster.com

Private Sub Search_Click()
Me![datefield].SetFocus
Dim strStudentRef As String
Dim strSearch As String
If IsNull(Me![datefield]) Then
MsgBox "Please enter a Date!", vbOKOnly, "Invalid Search Criterion!"
Me![datefield].SetFocus
Exit Sub
End If
DoCmd.OpenForm "ROYAL DISCOUNT STORE"
DoCmd.GoToControl ("date")
DoCmd.FindRecord Me!datefield

End Sub
Post the code as it is now, please.
Hi!
i have search form and i did code for null value for date but i also need
[quoted text clipped - 3 lines]
thanks
lavesh
 
K

Klatuu

It appears there are more than one form involved here. It is not clear what
you are doing.
Can you describe what you are trying to accomplish?

laveshhp via AccessMonster.com said:
Private Sub Search_Click()
Me![datefield].SetFocus
Dim strStudentRef As String
Dim strSearch As String
If IsNull(Me![datefield]) Then
MsgBox "Please enter a Date!", vbOKOnly, "Invalid Search Criterion!"
Me![datefield].SetFocus
Exit Sub
End If
DoCmd.OpenForm "ROYAL DISCOUNT STORE"
DoCmd.GoToControl ("date")
DoCmd.FindRecord Me!datefield

End Sub
Post the code as it is now, please.
Hi!
i have search form and i did code for null value for date but i also need
[quoted text clipped - 3 lines]
thanks
lavesh
 
L

laveshhp via AccessMonster.com

ok
i have one form call " royal discount store" now i need a seach form which
have one txtbox

"date" and one cmd button 'search' now i need a code for search button if
date value is null get a message " please enter date" and if date not match
with my record then get message " 0 recored found" an if found record then
open form with recored in edit mode

thanks for help
It appears there are more than one form involved here. It is not clear what
you are doing.
Can you describe what you are trying to accomplish?
Private Sub Search_Click()
Me![datefield].SetFocus
[quoted text clipped - 18 lines]
 
K

Klatuu

It is much easier to just put your search control on your main form. Then
use the After Update event of the control to do the search.

Private Sub datefield_AfterUpdate()
Dim rst As Recordset

If IsNull(Me![datefield]) Then
MsgBox "Please enter a Date!", vbOKOnly, "Invalid Search Criterion!"
Else
Set rst = Me.RecordsetClone
rst.FindFirst "[TableDateField] = #" & Me.datefield & "#"
If rst.NoMatch Then
MsgBox "No Matching Records Found"
Else
Me.Bookmark = rst.Bookmark
End If
Set rst = Nothing
End If
End Sub




laveshhp via AccessMonster.com said:
ok
i have one form call " royal discount store" now i need a seach form which
have one txtbox

"date" and one cmd button 'search' now i need a code for search button if
date value is null get a message " please enter date" and if date not match
with my record then get message " 0 recored found" an if found record then
open form with recored in edit mode

thanks for help
It appears there are more than one form involved here. It is not clear what
you are doing.
Can you describe what you are trying to accomplish?
Private Sub Search_Click()
Me![datefield].SetFocus
[quoted text clipped - 18 lines]
thanks
lavesh
 
D

Douglas J. Steele

In case the user's Short Date format is other than mm/dd/yyyy in Regional
Settings, it's better to use:

rst.FindFirst "[TableDateField] = " & Format(Me.datefield,
"\#mm\/dd\/yyyy\#")

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Klatuu said:
It is much easier to just put your search control on your main form. Then
use the After Update event of the control to do the search.

Private Sub datefield_AfterUpdate()
Dim rst As Recordset

If IsNull(Me![datefield]) Then
MsgBox "Please enter a Date!", vbOKOnly, "Invalid Search
Criterion!"
Else
Set rst = Me.RecordsetClone
rst.FindFirst "[TableDateField] = #" & Me.datefield & "#"
If rst.NoMatch Then
MsgBox "No Matching Records Found"
Else
Me.Bookmark = rst.Bookmark
End If
Set rst = Nothing
End If
End Sub




laveshhp via AccessMonster.com said:
ok
i have one form call " royal discount store" now i need a seach form
which
have one txtbox

"date" and one cmd button 'search' now i need a code for search button if
date value is null get a message " please enter date" and if date not
match
with my record then get message " 0 recored found" an if found record
then
open form with recored in edit mode

thanks for help
It appears there are more than one form involved here. It is not clear
what
you are doing.
Can you describe what you are trying to accomplish?

Private Sub Search_Click()
Me![datefield].SetFocus
[quoted text clipped - 18 lines]
thanks
lavesh
 
K

Klatuu

Being U.S. based, I keep forgetting that. Thanks, Douglas.

Of course, the easy way would be if the rest of the world adopted the U.S.
date formats :)

Douglas J. Steele said:
In case the user's Short Date format is other than mm/dd/yyyy in Regional
Settings, it's better to use:

rst.FindFirst "[TableDateField] = " & Format(Me.datefield,
"\#mm\/dd\/yyyy\#")

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Klatuu said:
It is much easier to just put your search control on your main form. Then
use the After Update event of the control to do the search.

Private Sub datefield_AfterUpdate()
Dim rst As Recordset

If IsNull(Me![datefield]) Then
MsgBox "Please enter a Date!", vbOKOnly, "Invalid Search
Criterion!"
Else
Set rst = Me.RecordsetClone
rst.FindFirst "[TableDateField] = #" & Me.datefield & "#"
If rst.NoMatch Then
MsgBox "No Matching Records Found"
Else
Me.Bookmark = rst.Bookmark
End If
Set rst = Nothing
End If
End Sub




laveshhp via AccessMonster.com said:
ok
i have one form call " royal discount store" now i need a seach form
which
have one txtbox

"date" and one cmd button 'search' now i need a code for search button if
date value is null get a message " please enter date" and if date not
match
with my record then get message " 0 recored found" an if found record
then
open form with recored in edit mode

thanks for help

Klatuu wrote:
It appears there are more than one form involved here. It is not clear
what
you are doing.
Can you describe what you are trying to accomplish?

Private Sub Search_Click()
Me![datefield].SetFocus
[quoted text clipped - 18 lines]
thanks
lavesh
 
L

laveshhp via AccessMonster.com

thanks for your reply but i don't want to use main form , is it any way i can
use separate form for search
thanks

It is much easier to just put your search control on your main form. Then
use the After Update event of the control to do the search.

Private Sub datefield_AfterUpdate()
Dim rst As Recordset

If IsNull(Me![datefield]) Then
MsgBox "Please enter a Date!", vbOKOnly, "Invalid Search Criterion!"
Else
Set rst = Me.RecordsetClone
rst.FindFirst "[TableDateField] = #" & Me.datefield & "#"
If rst.NoMatch Then
MsgBox "No Matching Records Found"
Else
Me.Bookmark = rst.Bookmark
End If
Set rst = Nothing
End If
End Sub


ok
i have one form call " royal discount store" now i need a seach form which
[quoted text clipped - 16 lines]
 
L

laveshhp via AccessMonster.com

thanks for your reply but i don't want to use main form , is it any way i can
use separate form for search
thanks
Being U.S. based, I keep forgetting that. Thanks, Douglas.

Of course, the easy way would be if the rest of the world adopted the U.S.
date formats :)
In case the user's Short Date format is other than mm/dd/yyyy in Regional
Settings, it's better to use:
[quoted text clipped - 47 lines]
 
K

Klatuu

Yes, but it is more complex and takes more coding.
What you have to do in the is use a DLookup to determine if the value being
searched is found or not. Then you have to code for what to do if the user
finds a value or if not, whether they cancel the search or try the search
again. If the user find a good value, put the value in a control on the main
form.

Then in the main form, use the value received from the search form to
postion the form at the selected record or if the search was aborted in the
search form, not continue with the search.

laveshhp via AccessMonster.com said:
thanks for your reply but i don't want to use main form , is it any way i can
use separate form for search
thanks
Being U.S. based, I keep forgetting that. Thanks, Douglas.

Of course, the easy way would be if the rest of the world adopted the U.S.
date formats :)
In case the user's Short Date format is other than mm/dd/yyyy in Regional
Settings, it's better to use:
[quoted text clipped - 47 lines]
thanks
lavesh
 
L

laveshhp via AccessMonster.com

thanks for your reply
now is it possible if i use search in main form but it show me a first record
i need to form blank and after user put search date then data comes in for
(if the date match)
Yes, but it is more complex and takes more coding.
What you have to do in the is use a DLookup to determine if the value being
searched is found or not. Then you have to code for what to do if the user
finds a value or if not, whether they cancel the search or try the search
again. If the user find a good value, put the value in a control on the main
form.

Then in the main form, use the value received from the search form to
postion the form at the selected record or if the search was aborted in the
search form, not continue with the search.
thanks for your reply but i don't want to use main form , is it any way i can
use separate form for search [quoted text clipped - 10 lines]
thanks
lavesh
 
K

Klatuu

Yes. To present a blank form when it is loaded, position the form on a new
record in the Form's Load event:
docmd.GoToRecord acDataForm, Me.Name, acNewRec

Then in the After Update event of the search box:

Dim rst As Recordset

Set rst = Me.RecordsetClone
rst.FindFirst "[TableFieldName] = '" & Me.ControlName & "'"
If rst.NoMatch Then
MsgBox "Record Not Found"
Else
Me.Bookmark = rst.Bookmark
End If
Set rst = Nothing


laveshhp via AccessMonster.com said:
thanks for your reply
now is it possible if i use search in main form but it show me a first record
i need to form blank and after user put search date then data comes in for
(if the date match)
Yes, but it is more complex and takes more coding.
What you have to do in the is use a DLookup to determine if the value being
searched is found or not. Then you have to code for what to do if the user
finds a value or if not, whether they cancel the search or try the search
again. If the user find a good value, put the value in a control on the main
form.

Then in the main form, use the value received from the search form to
postion the form at the selected record or if the search was aborted in the
search form, not continue with the search.
thanks for your reply but i don't want to use main form , is it any way i can
use separate form for search
[quoted text clipped - 10 lines]
thanks
lavesh
 
Top