By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,080 Members | 1,855 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,080 IT Pros & Developers. It's quick & easy.

Pass data from original form to new form

100+
P: 147
Hi,
I have a form from which I open another form unsing the after update of a field I want to pass data from four fields of the original form to for fields of the newly opened form. I keep getting an error saying you can't assigne a value to this object.

My after update is

Expand|Select|Wrap|Line Numbers
  1. Private Sub Officer_LostFocus()
  2.  
  3.  If Me.Dirty Then Me.Dirty = False
  4.  
  5.   Dim stDoc As String
  6.  
  7.   stDocO = "frmOfficerRatings"
  8.  
  9.   DoCmd.OpenForm stDocO, , , , , , Me.RateeId & ";" & Me.RaterID & ";" & Me.RatingPeriod & ";" & Me.RatingDate
  10.  
  11.   DoCmd.GoToControl "GeneralAppearance"
  12.  
  13. End Sub
My On Open Form code in the form being opened is
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.  
  3.  If Len(Nz(Me.OpenArgs, "")) > 0 Then
  4.     SplitArgs = Split(Me.OpenArgs, ";")
  5.     OfficerID = SplitArgs(0)
  6.     RaterID = SplitArgs(1)
  7.     RatingMonth = SplitArgs(2)
  8.     RatingDate = SplitArgs(3)
  9.  End If
  10.  
  11. End Sub
Also I can not figure out how to make the on open code option explicit. If I use Dim As String it errors saying it expected an array.

Please halp!!!!
Thanks
Dan
Mar 26 '10 #1
Share this Question
Share on Google+
5 Replies


NeoPa
Expert Mod 15k+
P: 31,494
This could be a lot easier if you used punctuation Dan. I feel like a translator working out what you're trying to say. Please be more considerate in future posts.

As for your problem with the "you can't assigne a value to this object" error message, can you say which line of code this is triggered on? I can't see anything obvious that you've got wrong.

For your second question try Require Variable Declaration. That should explain everything quite clearly.
Mar 26 '10 #2

ADezii
Expert 5K+
P: 8,638
  1. Code in the Form's Open Event:
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Form_Open(Cancel As Integer)
    2. Dim varSplitArgs As Variant
    3.  
    4. 'Not sure of Data Types, or even if NULLs can be
    5. 'passed, so I made all Variables Variants
    6. Dim varOfficerID As Variant
    7. Dim varRaterID As Variant
    8. Dim varRatingMonth As Variant
    9. Dim varRatingDate As Variant
    10.  
    11. If Len(Nz(Me.OpenArgs, "")) > 0 Then
    12.   varSplitArgs = Split(Me.OpenArgs, ";")
    13.     varOfficerID = varSplitArgs(0)
    14.     varRaterID = varSplitArgs(1)
    15.     varRatingMonth = varSplitArgs(2)
    16.     varRatingDate = varSplitArgs(3)
    17.  End If
    18.  
    19.  
    20. Debug.Print "Officer ID: " & varOfficerID
    21. Debug.Print "Rater ID: " & varRaterID
    22. Debug.Print "Rating Month: " & varRatingMonth
    23. Debug.Print "Rating Date: " & varRatingDate
    24. End Sub
  2. Sample Usages:
    Expand|Select|Wrap|Line Numbers
    1. DoCmd.OpenForm "Orders", acNormal, , , acFormEdit, acWindowNormal, _
    2.                 "G4199876DW" & ";" & "LKLKKUT" & ";" & "January" & _
    3.                 ";" & "3/27/2010"
    Expand|Select|Wrap|Line Numbers
    1. DoCmd.OpenForm "Orders", acNormal, , , acFormEdit, acWindowNormal, _
    2.                 "G4199876DW" & ";" & Null & ";" & "January" & _
    3.                 ";" & Null
  3. Sample OUTPUTs:
    Expand|Select|Wrap|Line Numbers
    1. Officer ID: G4199876DW
    2. Rater ID: LKLKKUT
    3. Rating Month: January
    4. Rating Date: 3/27/2010
    Expand|Select|Wrap|Line Numbers
    1. Officer ID: G4199876DW
    2. Rater ID: 
    3. Rating Month: January
    4. Rating Date: 
Mar 29 '10 #3

100+
P: 147
Thanks for the help. I was able to get my code to work by placing the data from the existing form as default values in the form I open. However, I still can't understand why I get an error saying it "expected an array" when I try to use "Option Explicit" in the above posted on open code. I read the article NeoPa listed but I can't put my finger on the problem in my code.

Please help.

Thanks
Dan
Apr 5 '10 #4

ADezii
Expert 5K+
P: 8,638
Did you explicitly Declare SplitArgs as a Variant?
Apr 5 '10 #5

NeoPa
Expert Mod 15k+
P: 31,494
@DAHMB
You don't say on what line you see the error message, nor do you have any code where SplitArgs is Dimmed, but assuming it is line #4, then you cannot use SplitArgs to take the return value of Split() unless you Dim it as an array of an indeterminate number elements (or variant), as the Split() function returns an array.
Apr 8 '10 #6

Post your reply

Sign in to post your reply or Sign up for a free account.