Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to go back to previously opened form from POPUP

Posted on 2013-06-12
16
Medium Priority
?
343 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 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 39241786
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
ID: 39242348
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
ID: 39242356
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39242367
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
ID: 39242902
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 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39245884
upload a copy of your db..
0
 

Author Comment

by:TechGuise
ID: 39247477
this all starts on the "frmNewTicketEntry" form

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

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39247665
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
 

Author Comment

by:TechGuise
ID: 39247746
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 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39247818
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
ID: 39247858
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 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39247947
what exactly do you want this line to do "me.address = stAddr"  ?
0
 

Author Comment

by:TechGuise
ID: 39248060
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 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39248268
upload a db with the list box in the "frmDialogPhoneLU" populated with records.
0
 

Author Comment

by:TechGuise
ID: 39248287
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
ID: 39251303
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
When we develop an application in Ms Access 2016 we should also try to protect the queries, macros and table links. I know I may not have a permanent solution but for novice users, they will not manage to break your application. Below is the detail …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

578 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