Prefill a field off one form on to another

G

Guest

Hello,

I have a main form called "Activities". I am going to set up a command
button on it to open a smaller form called "GAP". What I would like to know
is:

When the user clicks on the button to open the GAP form from the Activities
form, can I have the information from the "RN" field in the Activities form
prefill to the RN field on the GAP automatically upon opening? This way, when
the form opens that field is already filled in? Remember I am still learning
so please simplify your answer. Any help would most appreciated.

Thank you!
 
G

Guest

With the command line to open the second form you can send values using the
OpenArgs.

docmd.OpenForm "GAP",,,,,,Me.RN

In the second form you can always refer to this number that you passing as
Me.OpenArgs

On the load event of the second form, GAP, write the code

Me.RNFieldNameInTheGAPForm = Me.OpenArgs
 
G

Guest

Hi, Doug.
When the user clicks on the button to open the GAP form from the Activities
form, can I have the information from the "RN" field in the Activities form
prefill to the RN field on the GAP automatically upon opening?

Yes. Just use the form's OpenArgs Property. For example, if the text box
containing the RN value were named txtRN in both forms and the button was
named OpenGAPBtn, then try the following code:

' In the Activities form's code module:

Private Sub OpenGAPBtn_Click()

On Error GoTo ErrHandler

DoCmd.OpenForm "GAP", , , , , , Me!txtRN.Value

Exit Sub

ErrHandler:

MsgBox "Error in OpenGAPBtn_Click( ) in" & vbCrLf & Me.Name & _
" form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear

End Sub

' In the GAP form's code module:

Private Sub Form_Open(Cancel As Integer)

On Error GoTo ErrHandler

If (Len(Me.OpenArgs) > 0) Then
Me!txtRN.Value = Me.OpenArgs
End If

Exit Sub

ErrHandler:

MsgBox "Error in Form_Open( ) in" & vbCrLf & Me.Name & _
" form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear

End Sub

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 
G

Guest

It doesn't seem to work. I am either getting a compile error or a error #0.
Maybe I did something wrong or it needs additional clarification?

Thanks!
 
G

Guest

Can you post the Open form command line you are using
And the code where you assigned the OpenArgs value, and in which event
 
G

Guest

Hi Guys,

Management decided they do not want it to prefill, they want the user to
enter the number manually to match whatever record they are currently working
on which may not always be in order. Thank you for your help. As always I
appreciate your time and assistance in following up with me.

Have a great day and thank you again!!
 
6

'69 Camaro

You're welcome! At least you know how to do it if management ever changes
their minds, which often happens when data entry errors start costing big
bucks.

And please consider marking the replies you received as answers to your
question, since others who have the same question will be able to search for
and find these answers if you do so. Otherwise, unanswered questions expire
after a reasonable period of time to make way for new questions in the
database, so this one will be gone if you need to revisit the answers you've
received.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember
that questions answered the quickest are often from those who have a history
of rewarding the contributors who have taken the time to answer questions
correctly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top