Solved

How to go back to previously opened form from POPUP

Posted on 2013-06-12
16
334 Views
Last Modified: 2013-06-16
Hello,
I have a form called "frmNewTicketEntry", normally user selects the customer from a combo box.
I'm trying to give them the ability to type in a phone#, in the AFTERUPDATE event of the phone# control, I have it opening a POPUP form with a listbox that represents any customers that have that phone# in any of the Phone # fields (Cell, Work, Home, etc...)

When it opens the popup, it sets which form it came from in an unbound control called FROMFORM, (doing this in case I want to use same phone search method on other forms)

All good so far.
But when the user selects the right Customer from the list box and clicks the OK button, I want it to close the POPUP and set all of the necessary fields back on frmNewTicketEntry form.

My problem seems to be that frmNewTicketEntry isn't getting FOCUS.   I must be missing something simple, pretty sure I've accomplished this before.

thanks for any help.

This is the code that runs from Command button on popup form..............


Dim stCust As String
Dim stFromForm As String

stCust = Me.SearchList.Value
stFromForm = Me.FromForm.Value
DoCmd.Close acForm, "frmDialogPhoneLU"

DoCmd.SelectObject acForm, stFromForm, False

Dim stAddr As String
Dim stCity As String
Dim stState As String
Dim stZip As String

stAddr = Nz(DLookup("[Addr1]", "tblContacts", "[Numb] = " & stCust), "")
stCity = Nz(DLookup("[City]", "tblContacts", "[Numb] = " & stCust), "")
stState = Nz(DLookup("[State]", "tblContacts", "[Numb] = " & stCust), "")
stZip = Nz(DLookup("[Zip]", "tblContacts", "[Numb] = " & stCust), "")

Me.Address.Value = stAddr
Me.CityStateZip.Value = stCity & "  " & stState & "  " & stZip
Me.CustNo.Enabled = False
Me.Address.Enabled = False
Me.CityStateZip.Enabled = False
me.phone.Enabled = False

Open in new window

0
Comment
Question by:TechGuise
  • 9
  • 7
16 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
change this

DoCmd.SelectObject acForm, stFromForm, False

with

Forms(stFromForm).setfocus


another option is to open your popup form in dialog mode

docmd.openform "NameOFForm",,,,,acdialog
0
 

Author Comment

by:TechGuise
Comment Utility
Thanks, Tried both.
When I try to open in dialog mode ",,,acdialog" it doesn't set the unbound control to the 1st form name.

This is what I'm using.
Dim stFrom As String
Dim stForm As String

stFrom = Me.Name
stForm = "frmDialogPhoneLU"

DoCmd.OpenForm stForm, , , , , acDialog
DoCmd.SelectObject acForm, stForm, False
Forms(stForm).SetFocus

Forms(stForm).FromForm.Value = stFrom

Open in new window

0
 

Author Comment

by:TechGuise
Comment Utility
When I open in normal (not acdialog), it seems to still not give focus to 1st form.

I've stripped it back to this, it stops on the last line.

Dim stCust As String
Dim stFromForm As String

stCust = Me.SearchList.Value
stFromForm = Me.FromForm.Value

DoCmd.Close acForm, "frmDialogPhoneLU"

DoCmd.SelectObject acForm, stFromForm, False
Forms(stFromForm).SetFocus
stCurrForm = Me.Name

Open in new window

0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
my first statement states,

change this

DoCmd.SelectObject acForm, stFromForm, False

with

Forms(stFromForm).setfocus


you are combining your codes with my suggestion, and the opening of the form in dialog is,

as i have stated is ANOTHER option


try my first suggestion first...
0
 

Author Comment

by:TechGuise
Comment Utility
Sorry for confusion.   The second post was tried "without" opening the form in Dialog mode.
(although I will admit that I did try BOTH suggestions at same time too)  :o)

it still hangs up when it gets to that "Me." statement.
stCurrForm = Me.Name

error = Invalid procedure call or argument

Thanks for help
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
upload a copy of your db..
0
 

Author Comment

by:TechGuise
Comment Utility
this all starts on the "frmNewTicketEntry" form

(Edit: Redacted - Modulus_Twelve)
(http://www.experts-exchange.com/R_20946.html)
SaleProgV1D-Redacted.zip
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
use these codes


Private Sub Command13_Click()
Dim stCust As String
Dim stFromForm As String
stFromForm = Me.FromForm.Value

If Me.SearchList & "" = "" Then
     MsgBox "No item selected from lists!"
     DoCmd.Close acForm, "frmDialogPhoneLU"

     Forms(stFromForm).SetFocus
     Exit Sub
End If

stCust = Me.SearchList.Value

DoCmd.Close acForm, "frmDialogPhoneLU"

Forms(stFromForm).SetFocus

End sub
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:TechGuise
Comment Utility
In the database copy that I uploaded, I inserted the text you sent me.   It still hangs up when it gets to the first "Me." instance.   ( was using the "Me.Name" to try and determine which form had focus)

It does let user no if nothing was selected, I like that.  Thanks!

Private Sub Command13_Click()

'from Capricorn:::::::::::::::::
Dim stCust As String
Dim stFromForm As String
stFromForm = Me.FromForm.Value

If Me.SearchList & "" = "" Then
     MsgBox "No item selected from lists!"
     DoCmd.Close acForm, "frmDialogPhoneLU"
     Forms(stFromForm).SetFocus
     Exit Sub
End If
stCust = Me.SearchList.Value
DoCmd.Close acForm, "frmDialogPhoneLU"
Forms(stFromForm).SetFocus

'from Capricorn::::::::::

stCurrForm = Me.Name
Debug.Print stCurrForm


Dim stAddr As String
Dim stCity As String
Dim stState As String
Dim stZip As String
Dim stTaxExempt As String
Dim stTaxFormDate As String
Dim stDefaultTaxRate
Dim stTaxExemptStatus As String

stDefaultTaxRate = DLookup("[FieldValue]", "tblParameters", "[FieldName] = 'DefaultTax'")
stAddr = Nz(DLookup("[Addr1]", "tblContacts", "[Numb] = " & stCust), "")
stCity = Nz(DLookup("[City]", "tblContacts", "[Numb] = " & stCust), "")
stState = Nz(DLookup("[State]", "tblContacts", "[Numb] = " & stCust), "")
stZip = Nz(DLookup("[Zip]", "tblContacts", "[Numb] = " & stCust), "")
stTaxFormDate = Nz(DLookup("[TaxFormRecvd]", "tblContacts", "[Numb] = " & stCust), "")
'stTaxExempt = Nz(DLookup("[TaxExempt]", "tblContacts", "[Numb] = " & stCust), "")

'If stTaxExempt = -1 Then Me.TaxExemptStatus.Value = "Exempt"


Me.Address.Value = stAddr
Me.CityStateZip.Value = stCity & "  " & stState & "  " & stZip
Me.SalesTaxRate.Value = stDefaultTaxRate
'Me.TaxExemptStatus = stTaxExempt
Me.ExemptCertFiled.Value = stTaxFormDate
Me.frmNewTicketEntryItems.SetFocus
Me.CustNo.Enabled = False
Me.Address.Enabled = False
Me.CityStateZip.Enabled = False
Me.phone.Enabled = False

End Sub

Open in new window

0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
i am really not sure what you are up to...
your question was to go back to the calling form when the popup form was close..

this is the codes that you will use, nothing more



Private Sub Command13_Click()
Dim stCust As String
Dim stFromForm As String
stFromForm = Me.FromForm.Value

If Me.SearchList & "" = "" Then
     MsgBox "No item selected from lists!"
     DoCmd.Close acForm, "frmDialogPhoneLU"

     Forms(stFromForm).SetFocus
     Exit Sub
End If

stCust = Me.SearchList.Value

DoCmd.Close acForm, "frmDialogPhoneLU"

Forms(stFromForm).SetFocus

End sub








.

i don't know why you need this line

stCurrForm = Me.Name

and the codes that follows..
0
 

Author Comment

by:TechGuise
Comment Utility
When focus gets back to the original form, I am wanting to fill in the Name, Address, City, State, etc.... based on the selection made on the List Box on the popup form.

Sorry, guess I wasn't clear in my original question...........
>>>>>
 "But when the user selects the right Customer from the list box and clicks the OK button, I want it to close the POPUP and set all of the necessary fields back on frmNewTicketEntry form."
>>>>>

Even if I take out the stCurrForm, it will error out at "me.address = stAddr"
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
what exactly do you want this line to do "me.address = stAddr"  ?
0
 

Author Comment

by:TechGuise
Comment Utility
it is supposed to set the "Address" field in the tblOpenSalesTickets table, by setting the value of the "Address" control on the "frmNewTicketEntry " form.

I was getting the value from the tblContacts table when the user selected a name from the ListBox on the "frmDialogPhoneLU" form.
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
upload a db with the list box in the "frmDialogPhoneLU" populated with records.
0
 

Author Comment

by:TechGuise
Comment Utility
If you type in 1234567890 as the phone number on the frmNewTicketEntry  and hit ENTER, it will bring up the  frmDialogPhoneLU form with contacts that have matching phone #'s in the list.

The criteria for that list is set to look at all phone number fields in the tblContacts table.  

There are 6 or 7 records in tblContacts with various phones #'s.

2222222222
3333333333
2145551212

Thanks
0
 

Author Closing Comment

by:TechGuise
Comment Utility
Problem solved.  

Although I never really figured out how to be able to use "Me.xxx" to set the value of various controls on the original form, I was able to get them set using the example below.  (method to set focus in your 1st response).   Sorry to take up your time.

                 Forms(stFromForm).address.value = staddr

Thanks for the help!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Lync meeting or Lync conferencing is what many organizations would like to deploy to allow them save money. But companies are now giving up for various reasons, one of which is that they cannot join external meetings (non-federated company meetings)…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now