Copying data from previous record

  • Thread starter TonyWilliams via AccessMonster.com
  • Start date
T

TonyWilliams via AccessMonster.com

I have a form that has a combo box (cmbmonth) where the value is stored in a
field txtmonth. The users normally input a batch of records at a time. So
what I would like to happen is that they select a value from the combo box on
the first record but as they move to a new record the value is carried over
to the same control on the new record. This should happen with every new
record until they decide to select a new value and then that new value is
carried forward until they decide to select another new valu and so on.
Can anyone help with this?
Thanks
Tony
 
J

John W. Vinson

I have a form that has a combo box (cmbmonth) where the value is stored in a
field txtmonth. The users normally input a batch of records at a time. So
what I would like to happen is that they select a value from the combo box on
the first record but as they move to a new record the value is carried over
to the same control on the new record. This should happen with every new
record until they decide to select a new value and then that new value is
carried forward until they decide to select another new valu and so on.
Can anyone help with this?
Thanks
Tony

You can use the AfterUpdate event of a control to set that control's own
DefaultValue property:

Private Sub cmbMonth_AfterUpdate()
Me!cmbMonth.DefaultValue = """" & Me!cmbMonth & """"
End Sub

The quotes are required because (whatever the datatype of the field) the
default vallue must be a string.
 
T

TonyWilliams via AccessMonster.com

Thanks John I tried that and got an error message:
Runtime error 438
Object doesn't support this object or method.

When I looked at the VBA window after the full stop after nonth the only
choice I had was Value and not DefaultValue.

Any ideas?
Thanks for your help
Tony
I have a form that has a combo box (cmbmonth) where the value is stored in a
field txtmonth. The users normally input a batch of records at a time. So
[quoted text clipped - 6 lines]
Thanks
Tony

You can use the AfterUpdate event of a control to set that control's own
DefaultValue property:

Private Sub cmbMonth_AfterUpdate()
Me!cmbMonth.DefaultValue = """" & Me!cmbMonth & """"
End Sub

The quotes are required because (whatever the datatype of the field) the
default vallue must be a string.
 
J

John W. Vinson

Thanks John I tried that and got an error message:
Runtime error 438
Object doesn't support this object or method.

When I looked at the VBA window after the full stop after nonth the only
choice I had was Value and not DefaultValue.

This is clearly a typo, but I'm baffled by what "after nonth" might mean.

My suggestion was intended to be that you open the Form in design view; select
the combo box; view its Properties; and click the ... icon next to the
"AfterUpdate" line on the Events tab. If you then select "Code Builder" you
will be put into the VBA editor for that event, with the Sub and End Sub lines
filled in for you. You would type in

Me!cmbMonth.DefaultValue = """" & Me!cmbMonth & """"

between the Sub and End Sub lines.

If that isn't what you did, please explain.
 
T

TonyWilliams via AccessMonster.com

Hi John My apologies, yes it was a typo (brain working faster than the
fingers for a change!). What I did was exactly as you said and when it didn't
work I changed the ! to a full stop and then looked to see what the choices
were in the drop down list when I input a full stop after cmbmonth. That's
when I could only see Value as a choice. HOWEVER I 've just pasted your code
in again and this time it worked fine. No idea what I must have done the
first time.
Many thanks.
Tony
PS The problem with all of this is how do I get my ageing brain to remember
all these wonderful tips and hints that you guys give me so that I can use
them again? White cell deterioration is one of the most frustrating parts of
getting old!
 
J

John W. Vinson

PS The problem with all of this is how do I get my ageing brain to remember
all these wonderful tips and hints that you guys give me so that I can use
them again? White cell deterioration is one of the most frustrating parts of
getting old!

I'm 63 and I know JUST what you mean... in fact I wince a tiny bit when I see
your .sig! One reason I'm active here is to just keep my brain exercised. Good
luck and glad I was able to help!
 

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