Full Version: Problems with Tab Control implementation
UtterAccess Discussion Forums > Microsoft® Access > Access Q and A
Milster
Hi All
I've have been developing my own version of a database that Lou (kapeller) created. I have recently placed the old parent form from this database onto a page in a Tab Control and have got most things working fine.

The database returns search results to a subform called "frmSearchCriteriaSub". Say you have 3 search results displayed. If you do a new search that gets no hits, a msgbox is thrown saying so. After you "OK", the 3 hits you just got remain dispayed. So I want to work out how to follow that message box with a procedure that resets the "frmSearchCriteriaSub" form so that the user isn't confused by legacy results.

Before I moved the database design into a page on a Tab Control it used to launch with a blank display form. Now when it launches all of my records are displayed even though they are not meant to be. If I can work out how to force the main form to load without any results shown, I should be able to add that procedure to my search procedure mentioned above.

I've spent heaps of time trying to work it out and now have to resort to a plea for help.

Sorry I couldn't condense that any more. Attached is the original database(1) and the new project(2) with Tab Control.

Thanks
kapeller
Hi Milan

I decided to take a look at it tonight and it turned out to be a very simple job. I hope I have understood your and interpreted you issue.

See the attached DB Test 2-SampleSearch.mdb

The changes are as follows.

1.A module “modClearFormControls” that runs via the Clear button and clears all the forms controls of any text. Useful when there are lot of form controls. Take a look.
CODE
Function ClearFormControls(pF As Form)
    Dim ctl As Control
    On Error Resume Next
    For Each ctl In pF.Controls
        If ctl.ControlType Or acComboBox = acTextBox Then ctl.Value = Null
    Next ctl
End Function


2. On the frmSearchCriteriaMain I created a new bit of code. Take a look.

3. The code is called on the Form_Load and the cmdSearch_Click

I hope this is what you require.
Milster
Thanks Lou!

I'm still not there though...

1. When the database loads, even though a search has not been executed you can see all 6 records displayed. I'd like "frmSearchCriteriaSub" subform to be blank at startup. Like it is on your original.

2. Then if you search and get hits. Let's say 3 records are displayed. Fine.

3. Then you do another search type "gwawjr4g" in the Subject: search criteria. You get a "The search failed..." msgbox. After you click OK, I'd like "frmSearchCriteriaSub" to be blank again. Rather than still displaying the results from (2.) above.

Hope that is clearer.
Milster
kapeller
Hi Milster

I am a bit confused. I down loaded your original DB's from your post. This is 2-SampleSearch.mdb ??

When I open this DB the subform is blank.The changes made, particularly when you type "rtyhgfe" and click OK, both the main and sub forms are blank and do not have data.

Are we working off the same DB??
Milster
Absolutely. That is confusing. Yes I downloaded your file Test 2-SampleSearch.mdb. When I run it the main form is blank but the sub form is populated with the entire set of six records.

When I am referring to the sub form. I am talking about the rows of data (records) under the heading "Search Results".

Edited by: Milster on Mon May 19 9:59:40 EDT 2008.

Edited by: Milster on Mon May 19 10:00:50 EDT 2008.
kapeller
Hi Milster

I am about to go off to work.

When I get home later this afternoon I will take another look and get back to you.

Edited by: kapeller on Mon May 19 16:33:10 EDT 2008.
Milster
Thanks. Have we confirmed that we are seeing the same thing? Cheers
kapeller
Hi Milster!!!!

OK here is the issue!!!

What you need to work out is from where is frmSearchCriteriaMain form to start.

From the frmMainWindow form on the tab, or as a stand alone form.

If your start the frmSearchCriteriaMain form from the frmMainWindow the query need this statement in the SQL View in the query.

CODE
SELECT DISTINCT tblsubject.NewspaperID, tblsubject.Index, tblsubject.Title, tblsubject.AreaCode, tblsubject.NewsPaper, tblsubject.DateofPaper, tblsubject.Subject, tblsubject.CreateDate

FROM tblsubject

WHERE ((([Index] & "") Like IIf([Forms]![frmMainWindow]![frmSearchCriteriaMain]![Index] Is Null,"*",[Forms]![frmMainWindow]![frmSearchCriteriaMain]![Index] & "*")));


OR as a stand alone the SQL View in the query should be.

CODE
SELECT DISTINCT tblsubject.NewspaperID, tblsubject.Index, tblsubject.Title, tblsubject.AreaCode, tblsubject.NewsPaper, tblsubject.DateofPaper, tblsubject.Subject, tblsubject.CreateDate

FROM tblsubject

WHERE ((([Index] & "") Like IIf([Forms]![frmSearchCriteriaMain]![Index] Is Null,"*",[Forms]![frmSearchCriteriaMain]![Index] & "*")));


The difference in the SQL View is this [frmMainWindow]

Either way the frmSearchCriteriaMain will function as requested.

I hope this makes sense.

PS Were seeing the same database


Edited by: kapeller on Tue May 20 4:18:57 EDT 2008.
Milster
Hi again.

Yes I want it to start from the [frmMainWindow], but my original upload already has the query including the [frmMainWindow]! reference in the SQL.

Sorry, but I can't see why I can't wipe the results from view. Seems to all revolve around the lines...

CODE
Me.Index = -1
    frmSearchCriteriaSub.Requery
    Me.Index = Null


I've tried creating test buttons that trigger it specifically, but in my implementation they won't clear display form.

Ta
kapeller
Hi Milster!!!

You are right, but the version I attached earlier works as you want. On load the form controls are empty.

When there is not a mactch based on selected criteria, and when you click OK button of the message, the form controls are cleared.

I cannot see why it is not working.

When the frmMainWindow opens and the frmSearchCriteriaMain is on the tab the form controls are empty.

I have again attached your database.

I wait for your response .
Milster
Hi Lou.

Yes, the form contols are cleared BUT the 6 records remain displayed (or whatever the results of your previous search is).

I want a grey empty frmSearchCriteriaSub .

Your original DB called "2002SampleSearch.mdb" launches with a grey empty Search Results area. When you drop it into a parent form, and after you have made the neccessary SQL changes it behaves the way mentioned above. Plus you can't clear frmSearchCriteriaSub with a requery.

Milster
kapeller
Hi Milster!!

Attach the following code to the Clear button on the frmSearchCriteriaMain

CODE
Private Sub cmdClear_Click()
    ClearFormControls Me
    'Makes sure that the main and sub forms do not contain any data
    'on load until criteria is selected
    Call SetFormCrtlNull
End Sub


This code is already there SetFormCrtlNull

What you will then have to do before entering new criteria click the Clear button to empty the form controls.
Milster
Hi Lou

Did that. Still no clearing of the sub form results.
Very strange - I still can't work out why it is so hard to clear the display results. Must admit I tried similar methods before even posting this thread.

These methods work when the DB is run as a stand alone but fail once the DB is started from the tab control page.

Thanks
Milster
kapeller
Hi Milster

Thats very strange. I will keep looking to see if something has been missed. It works fine on my machine?
Milster
Strange indeed! I've tried it on 2 different machines running WinXP SP-2 and Access 2003 with the same problem behaviour. What setup do you have?

For anyone else that's interested in this thread. Would you mind looking at my original post and attachments:

"1-SampleSearch.mdb" launcehes with a grey blank Search Results area.
"2-SampleSearch.mdb" launches with 6 records displayed in Search Results area.

Can you confirm that this the case, or report as Lou has, that they both launch with blank Search Results.

Thanks

Edited by: Milster on Tue May 20 7:49:37 EDT 2008.
kapeller
Hi Milster

I have WinXP SP-2 and Access 2003
Milster
That is odd - hopefully others will offer their observations. Hard for you to help if it is working on your machine. Very confused. Milan

PS. All I can think of is some of those warnings that Access will throw when it launches. This machine has not asked me for a while. I think it was 1) Blocking unsafe expressions and the other was 2) Jet...

Is there a way to manually set those?
kapeller
Hi Milan!!!!!!!!!


I have gone through the code and i cannot see anythig that would prevent the DB from working on your PC. As I indicated earlier it now functions as expected.

So at this time I am stumped!!!!
Milster
Me too.

I'll keep testing on different machines at work and see if I can work out what the difference is.

Thanks for your time.
Milster
Milster
Hi Lou

I worked it out!

My earlier hunch was correct. It appears the culprit was Macro Security. I allowed unsafe expressions to run and then the DB performed the way we wanted it to.

Not sure why this is the case as it does not seem this was a code or macro issue but more a design change where we took a DB and moved it onto a tab control. But there you have it.

Any thoughts?

Milster
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.