简体   繁体   中英

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!

acDialog parameter causes code execution of first form to suspend until second form is closed. So either remove the parameter or place code in second form to populate its own record.

Pass value with OpenArgs argument:

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

To read OpenArgs property, code behind second form, possibly in the Current event:

If Me.NewRecord Then Me.txtUWI = Me.OpenArgs

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM