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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

close form and don't peform search

Status
Not open for further replies.

officemanager2

Technical User
Oct 11, 2007
116
CA
I have the following code tied into a button which is supposed to close the
form and put the enduser back at the switchboard.
Code:
Private Sub searchtoswitch_Click()
On Error GoTo Err_searchtoswitch_Click

   If Me.Dirty Then Me.Dirty = False
   DoCmd.Close acForm, "FNsearchform"

Exit_searchtoswitch_Click:
   Exit Sub

Err_searchtoswitch_Click:
   MsgBox Err.Description
   Resume Exit_searchtoswitch_Click
   
End Sub
The form uses combo boxes to search contacts in the database. The issue I'm
having is if the end user starts a search and then does not want to complete
they will ideally be able to hit the button and go back to the swtichboard.
What is happening though is when they click the button to close the form they
instead get sent to the closest record based on the search critiera entered
to that point.

I've tried Docmd.Open after the DoCmd.Close but this would not work.

Any suggestions?
 
I should have added the code for the search boxes

Code:
Private Sub FNcombobox_AfterUpdate()
Dim strWhere As String
If Not IsNull(Me.FNcombobox) Then
    strWhere = strWhere & " AND ID = " & Me.FNcombobox
    Me.FNcombobox = Null
End If
DoCmd.OpenForm "MailingList", , , Mid(strWhere, 6)
End Sub

I'm starting to think the way the 'End If' is set up that the change may have to occur there If I want the close button on this form to close to the switchboard and not open up a record.
 
How are ya officemanager2 . . .

In [blue]VBA[/blue] there is whats called [blue]priority of execution[/blue]! For you what this means is that [blue]VBA[/blue] in execution has priority over the [blue]User Interface[/blue] ... aka ... hitting the button you mentioned! The running VBA has to complete first, before the code in the button clicked (user interface) is executed. Can you see this!

As an example ... in my browser I enter the address [blue]dictionary.com[/blue]. The site opens and while the page is loading ... I'm able to type in [blue]Test[/blue] as the search criteria. You'll notice that the search doesn't start until the page is fully loaded. Loading the page has priority over the search criteria. The concept I'm trying to convey!

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
The search boxes must be able finish their 'job' before the button can accomplish its 'job'.

I'm thinking the code to execute the button must have to happen after the search has finished.

Once the search box finds anything it wants to open the record it has found.

As it stands right now the seach box must understand that even if it has finished its goal of finding an entry
the button must be available to perform its function.

The best i can think of right now is that either the search boxes need code to tell them that if the button to close
the form is pushed, the form can close, so the code to make the button function must be place before the
DoCmd.OpenForm.

Now even if this is correct I am unsure of how that would go?
 
Hi AceMan: If you're out there I must admit to being stuck. I believe I understand your analogy with the website but I can't put it into practice. I changed around the code so the searches excute with the return key, but the problem remains.

I added in a DoCmd so the button actually goes to the switch board which it was not doing before. Instead it was just clicking off and the switchboard just happened to be open.

It does seem as though the answer is close, but I cannot crack it. I don't know if this is my lack of intuitive VBA skills or I'm just thinking like a bonehead. I had a brief look at your most used threads but didn't see anything there.

Here's what I believe at this point.

The search in the combobox needs to come to a conclusion before the button to close the form can work.

The combobox's are set to Openform on the End if statement so this current setup with automatically go to the record that is found.

I need to stop the the afterupdate, or at the very least write the code so it does it's search and then comes to an end.

Or

Change the End If statment so the form that has the contacts does not open at that point and allows another option.

I'm looking around the net for something akin to 'Afterupdate stop code' and similar statements.

We'll see where it goes.

I like your input though, it pushes the direction of thinking more to the intuitive side so I'll keep working at it.
 
It's a shame I can't edit posts afterwords, or perhaps I can but cannot figure out where/how to do this.

Either way it seems I need to get the code to stop the comboboxs into the button code.

I've tried DoCmd.Close and a few other throws in the dark, but as of yet success is still a ways away.
 
Aceman if you see this post this is what I've changed.

I removed the afterupdate on the comboboxes and put the code on to search buttons.

This has solved the problem but the end result is not what I was hoping for. O'well, at least its working now.

thanks, I'm going to post a new problem, which of course is tied into search boxes.
 
officemanager2 . . .

Apologies for such a long delay, but you were so adamant about this I decided to wait.

As you've found out, there's no real way to prevent opening the [blue]MailingList[/blue]. Once a selection is made [blue]the code in the afterupdate event has to complete[/blue] ... 1st. On this basis I'd suggest a button on the [blue]MailingList[/blue] form that closes both forms.

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
officemanager2 . . .

Here's a routine you can use to close all open forms except the switchboard. Just copy/paste in a module in the modules window:
Code:
[blue]Public Sub SwBdOnly()
   Dim idx As Integer
   
   Do Until Forms.Count = 1
      If Forms(0).Name = "[purple][B][I]YourSwitchBoardFormName[/I][/B][/purple]" Then
         idx = 1
      Else
         idx = 0
      End If
      
      DoCmd.Close acForm, Forms(idx).Name, acSaveNo
   Loop

End Sub[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Hi Aceman: That code looks really interesting. Would it be best tide into a button or would one use it as an afterupdate to close the forms? Perhaps both, but I can only conclude that would create a conflict.

I find it curious there is no code to tell afterupdate that the afterupdate job has been completed and that it should stop.

Either way I'll keep at the VBA.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top