Copy one field to new record

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

Guest

I have a bound form with several fields. I need to copy one field value of
the current record to a new record when one is created using the navigation
buttons, not a command button. How can I make the default value for a new
record = the Model# field in the current record? I've tried several things,
the latest of which is:

Private Sub Form_Current()
If Me.NewRecord Then
[Forms]![NewPartInputfrm]![Model#].DefaultValue =
Forms![NewPartInputfrm]![Model#]
End If

At least I'm getting an error msg "type mismatch". I would think this would
be very simple, but I'm missing something. Thanks.
 
I haven't tested this, but I think it might work for you. Use the Form's
Current event. and the Tag property of your Model# control on your form (you
should not be using special characters like # in your naming, it causes extra
work and/or problems)

If Me.NewRecord Then
Me.txtModel = Me.txtModel.Tag
Else
Me.txtModel.Tag = Me.txtModel
End If

And in the After Update event of the control (so the tag property stays in
sync)

Me.txtModel.Tag = Me.txtModel
 
Alex said:
I have a bound form with several fields. I need to copy one field value of
the current record to a new record when one is created using the navigation
buttons, not a command button. How can I make the default value for a new
record = the Model# field in the current record? I've tried several things,
the latest of which is:

Private Sub Form_Current()
If Me.NewRecord Then
[Forms]![NewPartInputfrm]![Model#].DefaultValue =
Forms![NewPartInputfrm]![Model#]
End If

At least I'm getting an error msg "type mismatch".


The DefaultValue property is a string. Unless the field you
want to copy is a number type field, you need to enclose the
value in quotes:

Me![Model#].DefaultValue = """" & Me![Model#] & """"
 
Thanks so much Klatuu. It works perfect.

Klatuu said:
I haven't tested this, but I think it might work for you. Use the Form's
Current event. and the Tag property of your Model# control on your form (you
should not be using special characters like # in your naming, it causes extra
work and/or problems)

If Me.NewRecord Then
Me.txtModel = Me.txtModel.Tag
Else
Me.txtModel.Tag = Me.txtModel
End If

And in the After Update event of the control (so the tag property stays in
sync)

Me.txtModel.Tag = Me.txtModel

Alex said:
I have a bound form with several fields. I need to copy one field value of
the current record to a new record when one is created using the navigation
buttons, not a command button. How can I make the default value for a new
record = the Model# field in the current record? I've tried several things,
the latest of which is:

Private Sub Form_Current()
If Me.NewRecord Then
[Forms]![NewPartInputfrm]![Model#].DefaultValue =
Forms![NewPartInputfrm]![Model#]
End If

At least I'm getting an error msg "type mismatch". I would think this would
be very simple, but I'm missing something. Thanks.
 
Wow, here it is Friday and my brain is still functioning.
Glad it worked for you, it was totally air code :)

Alex said:
Thanks so much Klatuu. It works perfect.

Klatuu said:
I haven't tested this, but I think it might work for you. Use the Form's
Current event. and the Tag property of your Model# control on your form (you
should not be using special characters like # in your naming, it causes extra
work and/or problems)

If Me.NewRecord Then
Me.txtModel = Me.txtModel.Tag
Else
Me.txtModel.Tag = Me.txtModel
End If

And in the After Update event of the control (so the tag property stays in
sync)

Me.txtModel.Tag = Me.txtModel

Alex said:
I have a bound form with several fields. I need to copy one field value of
the current record to a new record when one is created using the navigation
buttons, not a command button. How can I make the default value for a new
record = the Model# field in the current record? I've tried several things,
the latest of which is:

Private Sub Form_Current()
If Me.NewRecord Then
[Forms]![NewPartInputfrm]![Model#].DefaultValue =
Forms![NewPartInputfrm]![Model#]
End If

At least I'm getting an error msg "type mismatch". I would think this would
be very simple, but I'm missing something. Thanks.
 

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

Back
Top