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

How to get data from one form to another 1

Status
Not open for further replies.

poporacer

Programmer
Oct 2, 2007
53
US
I have a form that has a combobox in it and when the NotInList event is fired, a new form is opened to enter the new data. I want the data that was input in the combobox to be in the text box when the input form opens. I also don't want all the error messages to pop up..ie...not in list. I tried the following code to prevent the error messages:

Reply = MsgBox("Do you want to add this Log Number to the Database?", vbYesNo, "Confirm Add new record")
If Reply = vbYes Then
DoCmd.RunCommand acCmdUndo
Response = acDataErrAdded
DoCmd.OpenForm "frmAddIncident", acNormal, , , acFormAdd, acWindowNormal
Me.Requery

But I think by doing so, it deletes the data that was put in the combobox. I still get the error pop ups.

Thanks for you assistance
 
This is exactly what I came to the Tek-Tips forums for....

I have one form that identifies the Project and I want that form to call another form that allows the user to make modifications to the project, but I need the form to pass the project name to the new form.

In VB6 this would be simple. I would just declare a Public Variable and its value would pass from Form to Form, but VBA doesn't work that way. So how do I pass variable information from one form to another in Access?
 
but VBA doesn't work that way
Really ?
Even if you declare your global variable in a standard code module ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
How are ya poporacer . . .

Be Aware: Your real problem is [blue]how you open the new form![/blue] Per your posted current code, not only does the new form open asynchronously when called, but the code in the [blue]NotInList[/blue] event continues to run asynchronously along with it. The point being, the [blue]NotInList[/blue] event completes before the new form is open! . . . [purple]See the poblem![/purple]

Also you say:
poporacer said:
[blue]I also don't want all the error messages to pop up..ie...not in list.[/blue]
Be Aware: For this event, you really need to afford the user the option to back out, [blue]rather than push an entry the user didn't intend![/blue]

Be Aware: After the new form is open the user can still decide to abort. The point being, [blue]the new form needs to have a way to indicate to the [blue]NotInList[/blue] event that entry was aborted![/blue] and action should be taken accordingly . . . Hope this makes sense!

To get on with resolution here, in the [blue]declaration section[/blue] of a module in the modules window, copy/paste the following line:
Code:
[blue]Public flgNIL as Boolean[/blue]
This is the indicator to the [blue]NotInList[/blue] event as to what happened in the new form!

Copy/paste the following to the [blue]NotInList[/blue] event of the combo:
Code:
[blue]   Dim Msg As String, Style As Integer, Title As String, DL As String
   
   DL = vbNewLine & vbNewLine
   Msg = "Do you want to add this Log Number to the Database?"
   Style = vbInformation + vbYesNo
   Title = "Confirm Add New Record! . . ."
   
   If MsgBox(Msg, Style, Title) = vbYes Then
      DoCmd.OpenForm "frmAddIncident", acNormal, , , acFormAdd, acDialog
      
      If flgNIL Then
         Response = acDataErrAdded
      Else
      End If
   Else
      Me!ComboboxName.Undo
      Response = acDataErrContinue
   End If[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
poporacer . . .

I hit submitt too soon . . .

What you return in [blue]flgNIL[/blue] when the new form is open is up to you! . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
That resolved part of the issue. The number is still in the combobox, but how do I access this number from the first form? And what is the purpose of flgNIL? It can only be a yes or no value (0, -1)?
 
poporacer . . .

Consider . . . when [blue]frmAddIncident[/blue] is closed, there's no way to know if a record was actually saved. What if the user aborts by simply closing the form! Hence the purpose of [blue]flgNIL[/blue]. Its up to code in [blue]frmAddIncident[/blue] to indicate this. When you do save a record you set flgNIL true.

While typing this, another [blue]fully automated[/blue] process hit me. It requires a little more code and gets rid of flgNIL. The process will be:
[ol][li]Get & hold the [blue]record count[/blue] of [blue]frmAddIncident[/blue] underlying table.[/li]
[li]Open [blue]frmAddIncident[/blue] [purple]modal[/purple].[/li]
[li]User closes [blue]frmAddIncident[/blue][/li]
[li]Code processing is now back in the calling form where another [blue]record count[/blue] is taken. If the user added a record, [blue]record count should be increased by 1![/blue] The difference in counts determines wether to use [blue]acDataErrAdded[/blue] or [blue]acDataErrContinue[/blue], with appropriate code.[/li][/ol]
As for picking up the combobox, in the [blue]Load[/blue] event of [blue]frmAddIncident[/blue]:
Code:
[blue]   Me![purple][b]TextboxName[/b][/purple] = Forms![purple][b]FormName[/b][/purple]![purple][b]ComboboxName[/b][/purple].Column(X)[/blue]
Where X is the column index (starts at zero) and includes all columns set to zero in the [blue]Column Widths[/blue] property of the combo.

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

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
AceMan,
After thinking about it I figured that was what the flgNil would be used for. I was curious why this would be needed? If you just requery the combobox after returning to the Form frmEdit you should have the correct list. Also, I tried the code for populating the textbox, it didn't work. I figured that was how but I originally had the code in the OnOpen event, so I moved it to the OnLoad event as you suggested. It still didn't work. I was going to attach the DB, but I guess you now need to have it on a server, I am at work and don't have access. I will post if necessary.

Thanks a Million in advance...you have been very helpful!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top