Access VBA. Two codes in same form (1 Viewer)

htadis

Registered User.
Local time
Today, 16:26
Joined
Dec 17, 2014
Messages
61
Good day !

i have a form where i put following two codes under two different controls.

for the control Vessel
Private Sub Vessel_AfterUpdate()
Me.Vessel.DefaultValue = """" & Me.Vessel.Value & """"
End Sub

for the control Combo121
Private Sub Combo121_AfterUpdate()
Me![Vessel] = Me![Combo121].column(0)
Me![Voyage] = Me![Combo121].column(1)
End Sub

How ever when these two codes put together, 1st code is not working.

could you pls assist me to get solve this problem.

Many thanks.
brgds
Htadis
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 03:56
Joined
Aug 30, 2003
Messages
36,118
What do you mean by "two codes put together" exactly? Setting the value would override the default.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 10:56
Joined
Feb 19, 2013
Messages
16,553
I presume you are wanting to update the default value to the last entry? if so then this

Me.Vessel.DefaultValue = """" & Me.Vessel.Value & """"

should simply be stated as

Vessel.DefaultValue = Me.Vessel

and this bit of code

Me![Vessel] = Me![Combo121].column(0)

does not generate an update event

you need to add another row below to call the procedure

Vessel_AfterUpdate

Note the default value is not retained when the form is closed unless you save the form (as opposed to the underlying data) or have some process to save the default value to a table on form close and repopulate when the form is opened again.
 

htadis

Registered User.
Local time
Today, 16:26
Joined
Dec 17, 2014
Messages
61
Thanks pbaldy for yr respond. i meant that i put them one after another.

i need to get done followings;

from the fist code, i need to fill some fields by a combo box single selection.

by the second code i need to carry over the default value to next record.

BUT when put the code for first one, second one is not working. that is my problem.

thanks.
 

htadis

Registered User.
Local time
Today, 16:26
Joined
Dec 17, 2014
Messages
61
CJ London,

Many thanks. I'll try as you said and revert. No, i do not need to get default value when the form is reopening. that is not necessary for my requirement. I just need to fill some fields by Combo box single selection and then carry over them to next record.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 03:56
Joined
Aug 30, 2003
Messages
36,118
Do you have it like this?

Code:
Private Sub Combo121_AfterUpdate()
  Me![Vessel] = Me![Combo121].column(0)
  Me![Voyage] = Me![Combo121].column(1)
  Me.Vessel.DefaultValue = """" & Me![Combo121].column(0) & """"
End Sub
 

htadis

Registered User.
Local time
Today, 16:26
Joined
Dec 17, 2014
Messages
61
Many thanks Paul. it works perfectly. :D
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 03:56
Joined
Aug 30, 2003
Messages
36,118
Happy to help!
 

Users who are viewing this thread

Top Bottom