Search Function Clearing all objects from my form

pcampos

Registered User.
Local time
Today, 03:56
Joined
Jan 20, 2010
Messages
12
Hi there...

I've successfuly created a form which includes a search box. However when a user search for an item that is not in the data, all the objects on the form disappear and I have to close the form to start again.
 
If

A form is bound to a record source

and

The record source is empty (as when your code returns no valid record)

and

New records cannot be added

no controls will show on the form or its tabbed pages.

The reasons that a bound form cannot have new records added include:
  1. AllowAdditions for the form is set to No
  2. The underlying query the form is based on is Read Only
  3. User doesn't have Write Permission for the folder where the data resides.
  4. Form's Recordset Type is set to Snapshot
To see if #2 is the case, from the Objects Dialog box go to Queries and click on the query that your form is based on to open it. Now try to enter a new record directly into the query. If you're unable to do so, this is the cause of your problem.

If your query is Read Only, follow this link to Allen Browne’s article explaining the reasons this happens.

http://allenbrowne.com/ser-61.html

If you cannot use any of these methods for whatever reason, an alternate approach would be to do a search first to see if a matching record exists and only attempt to retrieve it if that search finds such a record.

Linq ;0)>
 
Wow... that has worked. It was the very first reason, i had AllowAdditions for the form set to No, I changed to yes and now it works.

I have however a new question... On the same form I also have a GoTo Next record button but when i am on the last record if I keep pressing the button it throws a wobbly am it gives me the macro error window to say that "You can't go to the specified record"... I know that i am on the last record but how can I prevent this message showing up.

Is there a way of disabling the next record button when it reaches the last record?
 
Rather than disabling Nav buttons, I just throw up a warning to the user and don't allow the action to happen.

Here's the code I've used for years for this kind of thing:

Code:
Private Sub Form_Load()
  DoCmd.GoToRecord , , acNext
  DoCmd.GoToRecord , , acFirst
End Sub

Code:
Private Sub Next_Click()
  If CurrentRecord = RecordsetClone.RecordCount Then
    MsgBox "You are on the Last Record!"
  Else
    DoCmd.GoToRecord , , acNext
  End If
End Sub

Code:
Private Sub Previous_Click()
  If CurrentRecord = 1 Then
    MsgBox "You are on the First Record!"
  Else
   DoCmd.GoToRecord , , acPrevious
  End If
End Sub
 
Thank you very much... that has worked very well as well.
 

Users who are viewing this thread

Back
Top Bottom