Record search is bringing up a blank record when no record exists (1 Viewer)

RussellDeano

Registered User.
Local time
Today, 12:27
Joined
Aug 19, 2017
Messages
22
Good evening all,

I have a simple record search box (below). I would like an error to appear if no record exists for that number.

I am not familiar with code at the moment though and simply use macro builder (shown also)

Could anyone help with what i should input in the macro builder to return an error for no record existing?

Thank you
 

Attachments

  • Capture.JPG
    Capture.JPG
    40.4 KB · Views: 135
  • Capture2.JPG
    Capture2.JPG
    27.3 KB · Views: 130

pbaldy

Wino Moderator
Staff member
Local time
Today, 12:27
Joined
Aug 30, 2003
Messages
36,124
I don't use macros, but it looks like you can add an ElseIf. I'd try adding that and using a DCount() to test the source data with the same criteria. You could also make the textbox a combo that pulled existing records and set Limit to List to Yes.
 

ypma

Registered User.
Local time
Today, 20:27
Joined
Apr 13, 2012
Messages
643
I too don't use macros , but if you are happy to use a
[Event Procedure]of command button,.The search key is a text box which the record id you require is entered. I hope this will be of some use to you.

#Private Sub Command146_Click()
If IsNothing(Me.SearchKey) Then
MsgBox " pse enter a client id in searchKey Box"
Exit Sub
End If
Dim db As Database
Set db = CurrentDb
Dim rec As DAO.Recordset
Set rec = db.OpenRecordset("nameof recordsetw", dbOpenDynaset)
With rec
.FindFirst "[Client ID] = " & Me!SearchKey

If Not .NoMatch Then ' we found it
DoCmd.OpenForm "Name of form", wherecondition:="[Client ID] = " & Me!SearchKey
DoCmd.GoToControl "[client id]"

End If

If Not .NoMatch = False Then
MsgBox "No Match"
End If

End With
End Sub#


Regards Ypma
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:27
Joined
May 7, 2009
Messages
19,229
pay attention closely,
this is Macro only.

first make your Search form a Bound Form.
that means you need to Add your table
(Event_table or whatever name) as its
Record Source (Data->Record Source).

Add your EventID field to the form
and remove the label. Set its Visible
Property to No.

Next On the macro that you have just
follow the snapshot i made. on the SearchForRecord
macro, there is "Form11" there, replace it
with the name of your search form.
 

Attachments

  • aaMacroPart_1.png
    aaMacroPart_1.png
    10 KB · Views: 95
  • aaMacroPart_2.png
    aaMacroPart_2.png
    11.8 KB · Views: 92

Users who are viewing this thread

Top Bottom