Populating the Fields

G

Guest

Hi all,

I have a combo box, a text box (a date field) and a check box in the Record
Source of a form. Both combo box and text box are on the form and the check
box field is not on the form.

What I like to do is I like to write a code to automatically populate
today's date in the text box and check the box after a user has selected a
value from the combo box. If, for some reason, the user removes the value
from the combox box, the text box will not be populated and the check box
will not be checked for that record.

So I have tried the following code in the BeforeUpdate, and it's not working:

if Me.[combobox] <> null then
me.[textbox].value = now()
me.[checkbox] = "Yes"
end if

Please help. Thanks.
 
G

Guest

You cannot check for NULLs that way. In fact, if you try If NULL = NULL then,
the condition will *always* be False!!


Try this:

if Not IsNull(Me.[combobox]) then
me.[textbox].value = now()
me.[checkbox] = TRUE ' not "Yes"
end if


HTH
 
G

Guest

Hi SteveS,

Thanks for your help. It does not seem to be working.

When I have my cursor in the combo box field (before even selecting a
value), today's date automatically populates in the text box and a check also
automatically populates in the check box. If I select a value and then
remove it, both text and check box won't remove the date and check,
respectively.

My combo box displays a name on the form but populates an ID (numeric data
type) of that name in the table.

I inserted your code in the BeforeUpdate of the combo box. Did I do
something wrong?

Thanks.

SteveS said:
You cannot check for NULLs that way. In fact, if you try If NULL = NULL then,
the condition will *always* be False!!


Try this:

if Not IsNull(Me.[combobox]) then
me.[textbox].value = now()
me.[checkbox] = TRUE ' not "Yes"
end if


HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


Please Help said:
Hi all,

I have a combo box, a text box (a date field) and a check box in the Record
Source of a form. Both combo box and text box are on the form and the check
box field is not on the form.

What I like to do is I like to write a code to automatically populate
today's date in the text box and check the box after a user has selected a
value from the combo box. If, for some reason, the user removes the value
from the combox box, the text box will not be populated and the check box
will not be checked for that record.

So I have tried the following code in the BeforeUpdate, and it's not working:

if Me.[combobox] <> null then
me.[textbox].value = now()
me.[checkbox] = "Yes"
end if

Please help. Thanks.
 
G

Guest

You don't have code to remove the values in the controls.

I would probably have the code in the combo box after update event.

Try this:

If IsNull(Me.[combobox]) then
Me.[textbox] = NULL
Me.[checkbox] = FALSE
Else
Me.[textbox] = now()
Me.[checkbox] = TRUE
End If



HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


Please Help said:
Hi SteveS,

Thanks for your help. It does not seem to be working.

When I have my cursor in the combo box field (before even selecting a
value), today's date automatically populates in the text box and a check also
automatically populates in the check box. If I select a value and then
remove it, both text and check box won't remove the date and check,
respectively.

My combo box displays a name on the form but populates an ID (numeric data
type) of that name in the table.

I inserted your code in the BeforeUpdate of the combo box. Did I do
something wrong?

Thanks.

SteveS said:
You cannot check for NULLs that way. In fact, if you try If NULL = NULL then,
the condition will *always* be False!!


Try this:

if Not IsNull(Me.[combobox]) then
me.[textbox].value = now()
me.[checkbox] = TRUE ' not "Yes"
end if


HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


Please Help said:
Hi all,

I have a combo box, a text box (a date field) and a check box in the Record
Source of a form. Both combo box and text box are on the form and the check
box field is not on the form.

What I like to do is I like to write a code to automatically populate
today's date in the text box and check the box after a user has selected a
value from the combo box. If, for some reason, the user removes the value
from the combox box, the text box will not be populated and the check box
will not be checked for that record.

So I have tried the following code in the BeforeUpdate, and it's not working:

if Me.[combobox] <> null then
me.[textbox].value = now()
me.[checkbox] = "Yes"
end if

Please help. Thanks.
 
G

Guest

Hi SteveS,

Thanks again for your helps. For some reason, it only records the checkbox
in the table. The combo box and the text field values are not recorded in
the table.

Do you know why?

Thanks.

SteveS said:
You don't have code to remove the values in the controls.

I would probably have the code in the combo box after update event.

Try this:

If IsNull(Me.[combobox]) then
Me.[textbox] = NULL
Me.[checkbox] = FALSE
Else
Me.[textbox] = now()
Me.[checkbox] = TRUE
End If



HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


Please Help said:
Hi SteveS,

Thanks for your help. It does not seem to be working.

When I have my cursor in the combo box field (before even selecting a
value), today's date automatically populates in the text box and a check also
automatically populates in the check box. If I select a value and then
remove it, both text and check box won't remove the date and check,
respectively.

My combo box displays a name on the form but populates an ID (numeric data
type) of that name in the table.

I inserted your code in the BeforeUpdate of the combo box. Did I do
something wrong?

Thanks.

SteveS said:
You cannot check for NULLs that way. In fact, if you try If NULL = NULL then,
the condition will *always* be False!!


Try this:

if Not IsNull(Me.[combobox]) then
me.[textbox].value = now()
me.[checkbox] = TRUE ' not "Yes"
end if


HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


:

Hi all,

I have a combo box, a text box (a date field) and a check box in the Record
Source of a form. Both combo box and text box are on the form and the check
box field is not on the form.

What I like to do is I like to write a code to automatically populate
today's date in the text box and check the box after a user has selected a
value from the combo box. If, for some reason, the user removes the value
from the combox box, the text box will not be populated and the check box
will not be checked for that record.

So I have tried the following code in the BeforeUpdate, and it's not working:

if Me.[combobox] <> null then
me.[textbox].value = now()
me.[checkbox] = "Yes"
end if

Please help. Thanks.
 
G

Guest

SteveS,

I want to thank you again for your helps. Please ignore my previous
message. I forgot that I had a query set up to erase both combo box and text
field in the table.

You code works perfectly.

Thanks again. Have a nice weekend.

SteveS said:
You don't have code to remove the values in the controls.

I would probably have the code in the combo box after update event.

Try this:

If IsNull(Me.[combobox]) then
Me.[textbox] = NULL
Me.[checkbox] = FALSE
Else
Me.[textbox] = now()
Me.[checkbox] = TRUE
End If



HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


Please Help said:
Hi SteveS,

Thanks for your help. It does not seem to be working.

When I have my cursor in the combo box field (before even selecting a
value), today's date automatically populates in the text box and a check also
automatically populates in the check box. If I select a value and then
remove it, both text and check box won't remove the date and check,
respectively.

My combo box displays a name on the form but populates an ID (numeric data
type) of that name in the table.

I inserted your code in the BeforeUpdate of the combo box. Did I do
something wrong?

Thanks.

SteveS said:
You cannot check for NULLs that way. In fact, if you try If NULL = NULL then,
the condition will *always* be False!!


Try this:

if Not IsNull(Me.[combobox]) then
me.[textbox].value = now()
me.[checkbox] = TRUE ' not "Yes"
end if


HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


:

Hi all,

I have a combo box, a text box (a date field) and a check box in the Record
Source of a form. Both combo box and text box are on the form and the check
box field is not on the form.

What I like to do is I like to write a code to automatically populate
today's date in the text box and check the box after a user has selected a
value from the combo box. If, for some reason, the user removes the value
from the combox box, the text box will not be populated and the check box
will not be checked for that record.

So I have tried the following code in the BeforeUpdate, and it's not working:

if Me.[combobox] <> null then
me.[textbox].value = now()
me.[checkbox] = "Yes"
end if

Please help. 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

Top