PDA

View Full Version : Solved: Load Default Value in Form Control



Jacob Hilderbrand
06-11-2006, 12:10 PM
Hi

I would like to load a default value in a control on a form. The default value would change so I can't just add it to the properties of the control.

Basically what happens is the user opens a form and selects a username from a drop-down on a form, then that form will load another form whose data comes from a query showing only data for the selected user.

Now what I need to do is just make sure that the username is stored with each record that is added. So I don't want the user to be able to type in the text, I just want to autopopulate it.

Hopefully that all makes sense.

I tried some VBA, but it would not trigger (at least the way I thought it should).


Private Sub Form_BeforeInsert(Cancel As Integer)
UserName = "test"
End Sub


What I thought was when a new record was added, the textbox UserName would automatically be loaded with the text "test".

Thanks

boneKrusher
06-12-2006, 04:28 AM
You can put a default value in a control on the "on open" event.

for example

if isnull(me.username) then
me.username = "test"
else
end if

Jacob Hilderbrand
06-12-2006, 07:54 AM
But then when a new record is inserted, that field would be blank again, right?

boneKrusher
06-12-2006, 09:18 AM
Give it a try. It should be blank. Only when the form opens, will it default to "test"

Jacob Hilderbrand
06-12-2006, 10:18 AM
Right, but that is not the desired result. I want to load the value whenever you insert a new record.

Thanks

OBP
06-12-2006, 11:46 AM
Use if me.newrecord then
me.username = "test"

Jacob Hilderbrand
06-12-2006, 12:23 PM
Thanks

GaryB
06-13-2006, 10:05 AM
HI Drj,
This sound like something I use for customers. I have attaced a sample DB. Hope it helps.

Gary

3271

CFDM
06-19-2006, 01:49 PM
Me.txtType = "" [if it's text]
Me.txtEIC = 0 [if a number]
Use this on the onLoad event and after update event