Transfering Control Contents between 2 forms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form where Invoice information is entered into a subform. If an
Operation Code (OpCode) is entered into the dropdown that is not in the list
a form is opened to a new record so that the new Code can be entered with a
description using NotInList. This works fine. What I would like to do is
autopopulate the new record with the OpCode that was entered. I have tried
creating a variable stOpData. Here's my code

Dim stOpData As String

stOpData = me.[Operation]
stDocName = "Operation Codes"
DoCmd.OpenForm stDocName
DoCmd.GoToRecord , , acNewRec
[Forms]![Operation Codes]![Operation Code] = stOpData

It works if the variable is hard coded eg: stOpData = "00-904" but using
the control this way I get an "Invalid use of null" error

Any help would be greatly appreciated,
Thanks in Advance,

Pip'n
 
I solved the problem.. I didn't realize that the "Invalid use of Null" error
occurred because the control had not actually recorded the entered data and
that the NotInList event passes the entered data in the NewData parameter.

I'm now working on having the Invoice subform requery the entered data now
that it should be valid so that I may continue with my entry. I receive an
error that says "entry must be saved before this action can be performed"
meaning that i need a valid entry before i may requery the control.

Any suggestions.. thanks in advance
 
I've figured out the solution to my problem.

Here is my code in case anyone has the same problem or maybe if you might
have a better solution.

Private Sub Operation_NotInList(NewData As String, Response As Integer)

If MsgBox("Operation Code is not in list. Would you like to add it?", _
vbOKCancel) = vbOK Then
'Suppress Default Error message
Response = acDataErrContinue
' Enter valid choice to allow for requery
Me.Operation = "00"
' Open Form
stDocName = "Operation Codes"
DoCmd.OpenForm stDocName
DoCmd.GoToRecord , , acNewRec
' Enter attempted OpCode into OpCodes Form
[Forms]![Operation Codes]![Operation Code] = NewData
Else
' If user chooses Cancel, suppress error message
' and undo changes.
Response = acDataErrContinue
Me.Operation.Undo
End If

End Sub

and in the OK button of the Operation Codes Entry Form i placed this code:

Private Sub Close_OpCodes_Form_Click()
On Error GoTo Err_Close_OpCodes_Form_Click
' Determine if form was opened from a Work Order Entry
If IsLoaded("Work Orders") = True Then
' save new record
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
' refresh Operations drop down in Work Orders form
Forms![Work Orders]![Work Orders Subform].Form![Operation].Requery
' Update Work Order Operation Code
Forms![Work Orders]![Work Orders Subform].Form![Operation] =
Me.Operation_Code
End If
' Close Form
DoCmd.Close

Happy Coding
Cheers,
Pip'n
 
Back
Top