form question

S

Sean

I have a form with unbound text boxes, check boxes with labels, etc. After
I check all of my check boxes and fill in the text boxes I want to create a
button that will append all data on the form to a table. So if a check box
is checked, I want the text in the check box label to be appended to a field
in my table, in addition all text boxes that are filled in to be appened
to fields in my table. Some check boxes and text boxes will remain blank.
Can someone get me started with the code I would use for this? Thanks so
much.
 
O

Olduke

Sean said:
I have a form with unbound text boxes, check boxes with labels, etc. After
I check all of my check boxes and fill in the text boxes I want to create a
button that will append all data on the form to a table. So if a check box
is checked, I want the text in the check box label to be appended to a field
in my table, in addition all text boxes that are filled in to be appened
to fields in my table. Some check boxes and text boxes will remain blank.
Can someone get me started with the code I would use for this? Thanks so
much.

Highlight the Command button with the form in design view. Right click and
select Build Event, then select Code Builder
In the BeforeUpdate section of the button's enter the following code between
the existing lines:

If Check6 = -1 Then
[Name] = Text7
End if

We are assuming Check6 is the check button in question, Text7 is the textbox
that holds the data and [Name] is the field you wish to save the data to.

You will require these lines of code for every checkbox and textbox
combination you wish to save.

Don't forget, the form must have some underlying connection to the table you
wish to save the data in. I am also assuming you don't want to save the
checkbox results.
 
S

Steve Schapel

Sean,

Just wondering... you probably have a good reason for doing it this way,
but at the moment it seems strange that you don't just use a form bound
to your table, and enter your data directly, it would seem so much simpler.

Anyway, here is some skeleton air-code with the type of concept you are
suggesting:

Dim OneLabelToAdd As String
If Me.YourCheckbox Then
OneLabelToAdd = """" & Me.YourCheckbox.Caption & """"
Else
OneLabelToAdd = Null
End If
CurrentDb.Execute "INSERT INTO YourTable ( OneField, AnotherField,
FieldX )" & _
" VALUES ( '" & Me.TextTextbox & "', " & OneLabelToAdd & ", "
& Me.NumberTextbox & " )", dbFailOnError
 

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