[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Fill a field using another field from another form

Posted on 2012-04-13
5
Medium Priority
?
343 Views
Last Modified: 2012-04-13
I have a data entry form.  One of the fields on the form needs to be selected from a predefined list.   I tried using a combobox to provide this but the list is too big.

Instead I created a search form that opens when the user clicks a command button next to the field on the data entry form.

When this new search form opens the user has the ability to search and select the record they want.   I need the ID selected to be passed back to the Data Entry form.

I have tried instantiating the search form as an oject using code below that is executed from the Data Entry form.

'----------------------------
Dim f As New Form_Search

f.Modal = True
f.Visible = True
 
If f.SelectedItem > 0 Then
'use  f.SelectedItem
End If

Set f = Nothing
'------------------------------------
The problem is that this code continues to run after f.visible = true.   What I really want is to hold the code until it is hidden so that I reference and use  f.selected item.

Any ideas?
0
Comment
Question by:lee_jd
[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
  • 2
  • 2
5 Comments
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 1000 total points
ID: 37842616
to halt the codes after opening a form, open the form in dialog or modal mode

docmd.openform "formx",,,,, acdialog

the code will halt and continue when you close the form formx
0
 
LVL 17

Accepted Solution

by:
Natchiket earned 1000 total points
ID: 37842694
hi lee

An effective technique is to use the OpenForm method with the WindowMode set to acDialogue, this will suspend the calling code from running.

In the seach form once the user has selected an ID, run Me.Visible = False .. this will allow the calling code to to carry on

You then test for the presence of the search form in the calling code using syscmd e,g,

If syscmd(acSysCmdGetObjectState,acForm,"Search")=acObjStateOpen Then
    'if we go here we know that search form is open so retrieve ID
    ID = Forms!Search!Whateverfield
    DoCmd.Close, acForm, "Search"
Else
     ' if we go here the form was already closed by the user without specifying anything...
End IF
0
 
LVL 2

Author Closing Comment

by:lee_jd
ID: 37842899
Search form
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37842978
just wondering, how you can run codes from anywhere, when a form was open in dialog mode.
0
 
LVL 17

Expert Comment

by:Natchiket
ID: 37843013
if the dialog form sets its own visible propery to false it is no longer 'dialog' and the calling code will resume, at whch point it can retrieve stuff from the hidden form
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

650 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