Discussion Locked

Display MsgBox & don't open form if blan

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
HELP! I have a database that links to two seperate tables and my users can click a button and it pulls up all records that are related to the same SSN from both tables. PART 1 PROBLEM. How do I tell it to not open the form if there are no records and just display a message "no records found". PART 2 Currently it opens two seperate forms for each table because they hold different types of information. Is this the best way to display the records or can you display one form at a time and whenyou close it the other one pops up?

7 replies

by kevin.riggs

PART 1

Are you using ADO recordsets to return the records? If so, you can test against the RecordSet.RecordCount. If it is < 1 then you can display the messagebox. If you're not using ADO recordsets, please write how you're returning the records.

PART 2

If you want to open the window as modal then the user will have to deal with the first window before the 2nd is displayed.

An example:
If rs.RecordCount > 0 Then
frmReport1.Show vbModal
frmReport2.Show vbModal
Else
MsgBox "Error: blah, blah, blah", vbOKOnly
End If

by bambamz

Currently I have a form up and I input a SSN, it auto fills in the name. Then I click on a button that says Call History. With this event.

Dim stLinkCriteria As String

stLinkCriteria = "[SSN]=" & "'" & Me![dacalls.SSN] & "'"
DoCmd.OpenForm "FrmDAHistory", , , stLinkCriteria
DoCmd.OpenForm "FrmHistory", , , stLinkCriteria

these two forms come up whether there is information or not. The forms are built off of queries that query all of the calls in two different tables. So all I want to do is not have the form open and have a message display if there is no record found in the table.

by bob sellman

I'd suggest setting up a form using tabs. On the footer (or header if you prefer), you can have the SSN input and auto name display. The two tabs would be DA History and History. Each tab would have the appropriate subform (frmDAHistory or FrmHistory). Each subform would be linked to the main form by the SSN.

You wouldn't even need a Call History button. Just set the OnUpdate property of the SSN control on the main form to requery the two subform controls (after you make any appropriatechecks to be sure the SSN entered by the user is valid).

You might also want to set the subform controls visible property to false so they are not displayed when the form is opened. After a valid SSN is entered, make them visible and requery them. If an invalid SSN is entered, reset the two subform controls visible property to false.

This avoids having a bunch of forms opening at the same time. If there are no matching records for one of the tabs, then there will be no data displayed in that subform. But everything still will occur within the one form.

I've found that users relate fairly well to tabbed forms because of the analogy to file folders and because the concept is used elsewhere in Windows.

by bambamz

oh my goodness oh my goodness ANSWER 2 was soooo wonderful. It works so great. The subforms are sooo much easier, my users love it. THANK YOU THANK YOU THANK YOU

by bambamz

oops new at this. I closed the request. Hope you are still out there. I need to know how to hide the forms as false and then make the appear when the SSN matches.

This discussion is closed to new replies.