Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Want to create "Record Not Found" error message for form 1

Status
Not open for further replies.

carlcwc

Technical User
Sep 3, 2002
43
US
I have a form where the user enters an ID number-the form is linked to a parameter query.
My problem is that if the user enters a wrong or non-existing ID the form opens up blank.
I want an error message box to pop up informing the user that the ID is invalid and to try again.
Thanks in advance!
 
I am not to sure on how to get the msgbox to work however if you have space on your form, and would like to place a message there do this.

When I created something like this I created a label on my form, but did not type anything into it, instead I hit the spacebar 2 or 3 times and saved it that way. So when I looked at the form during runtime I would not see the label. Then I created a macro that on form load would goto a any textbox,(this is done because access will not let you create an if statement on a text box if the textbox does not have focus) once that textbox as the focus I went into the vb code and created an if statement that looks like this:

Private Sub MovName_GotFocus()
'Action that takes place if there is no records in the database
If MovName.Text = "" Then
Label1.ForeColor = 16737843(blue)
Label1.FontSize = 12
Label1.Caption = "Search completed"
Label42.Caption = "No records found with that name. Please click the 'Retry' button and check the spelling."
Label42.ForeColor = 255 (red)
Label42.FontSize = 12
Cmnd37.Caption = "Retry"
End If
End Sub

Now what happens is when I click on a button on my main menu that will open this query in form view I am asked to enter my data I want to search by, if my data is not correct the data base displays a message on one label (label1) that the "Search completed" and display a message on a second label (label42) that "No records found with that name. Plaeas check the spelling and click the retry button."

NOTE: The Retry button is a button that I placed on the form that most of the time when there are valid records displays a message "Search Again" but if the but using this if statement if there are no records on the first search then the button says "Retry".

I hope I could help you with your question.
 
Thanks for your suggestions, however, it didn't work. Perhaps its because the form is attached to a parameter query. What happens is that when someone attempts to use the search form, its the query paramater that pops up asking for a date. If there is no id matching, then all the user gets is a blank form.
Can you suggest a way for the query to show a null result/try again text box?
thanks
 
This is what I did,

I created a query that was based on the table in question. I then went into the design view of the query and for the criteria of the search field I placed this statement like [the text that you want to display on the search box] and then I save the query, create the "goto" macro for the form load, and then create the command that I showed you earlier. Now on thing I was wondering is are you have the form open up in read only view? If so that is your problem with the above command, now I am not sure why but you will get a blank screen if the form opens in read only with this code. If you do have the form opening in read only so that a record can not be changed, use the lock field option in the design mode under properties of the all the fields.

I hope that helps you out.

Let me know
 
This sounds useful, but I'm wondering about the goto Macro. Where does this get placed (in the form on open?)and what is the Macro "going to" if the form is already opened?
Thanks for all your help, I really appreciate it!
 
The goto macro will get placed in the onload of the form and you will want it to goto a control that you know will have data if there are any records, and will be blank if there are no records, meaning something that every record created will have, something that the user is required to provide when the record is added, but I don't recomend the primary key, just a reqiured field.

I hope this helps you let me know.
 
I have something similar on a keyword search, which also uses a parameter query:

' Purpose: Trigger error message if keyword criteria not met

Private Sub Form_Open(Cancel As Integer)
On Error GoTo ErrorForm

If Me.RecordsetClone.RecordCount = 0 Then
Cancel = True
MsgBox "There are no suspenses with that keyword" _
& vbCrLf & "Please verify you have typed it correctly", vbExclamation, _
"No Suspenses Found"

DoCmd.Close acForm, "frmKeywordOpen1"

Exit Sub

End If

ExitForm:
Exit Sub

ErrorForm:
MsgBox Err.Description
Resume ExitForm
Linda Adams
Linda Adams/Emory Hackman Official Web site Official web site for actor David Hedison:
 
Hey, you might know this,
The way I have set up one of my forms is so that when a user enters certain data the screen will move the controls around to meet the needs of the data. I am having problems with the tabindexing when the controls are moved is there a way to update the tab indexing when the controls are switched around.

NOTE: I tried to use the txtbox.tabindex = and then the number but that still did not work. can you give me some information

Thank you in advance,
 
Thanks all for the tips and assistance. Got exactly what I was looking for and a little extra for future use.
 
The easy is to use Dcount. If Dcount = 0 then no record.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top