Solved

How to go back to previously opened form from POPUP

Posted on 2013-06-12
16
339 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 7
16 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 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
 Database Backup and Recovery Best Practices

Join Percona’s, Architect, Manjot Singh as he presents Database Backup and Recovery Best Practices (with a Focus on MySQL) on Thursday, July 27, 2017 at 11:00 am PDT / 2:00 pm EDT (UTC-7). In the case of a failure, do you know how long it will take to restore your database?

 
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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
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 …
Suggested Courses

623 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