Search code examples
vbams-access

Access: trying to open a form and populate a textbox with the value from another form


Okay, I'm obviously doing something wrong, but can't figure out what it is, and this should be pretty simple.

I have a button on a form that opens another form and populates a textbox in the second form with a value from the first form.

Here is my code:

Private Sub test_Click()
DoCmd.OpenForm "subfrm_EA_COMMENT_ADD"
Forms!subfrm_EA_COMMENT_ADD.txtUWI = Me.txtUWI
End Sub

This works just fine, however I want the form to open in a dialog window, so I modified the script to this:

Private Sub test_Click()
DoCmd.OpenForm "subfrm_EA_COMMENT_ADD", acNormal, , , acFormAdd, acDialog
Forms!subfrm_EA_COMMENT_ADD.txtUWI = Me.txtUWI
End Sub

Now I am getting a run-time error 2450.

I've searched around regarding this error, but can't find any answers that work.

Can anyone point me in the right direction as to what I'm missing?

Thanks!


Solution

  • I found a work-around for this issue using a temp variable. I created a temp variable at the beginning of my Add Comment button, then set the unbound text box in the Comment dialog window to the value of the temp variable. This works like a charm and I can now open my windows in dialog instead of normal.

    I just wanted to let others know in case they run into this issue.