Add to table

A

Allison

Access 2003, Win XP

Is it possible to write a record to a table if a yes/no checkbox is ticked
by the user to yes on a form? The table I want to write to is not attached
to the form (a query is attached to the form).

If it is possible, please point me in the right direction to code this.

Thank you.

Allison
 
D

Douglas J. Steele

Best way is to use VBA.

Find the properties of the check box and look for the property associated
with the AfterUpdate event. Set the property to [Event Procedure], then
click on the ellipsis (...) to the right of the property. That will take you
into the VB Editor, in the middle of code that should look something like:

Private Sub NameOfCheckBox_AfterUpdate()

End Sub

Type the code between those two lines, so that you end up with something
like:

Private Sub NameOfCheckBox_AfterUpdate()

Dim strSQL As String

If Me!NameOfCheckBox Then
strSQL = "INSERT INTO MyTable (NumericField, TextField) " & _
"VALUES(" & Me!SomeNumericFieldOnForm & ", " _
"""" & Me!SomeTextFieldOnForm & """)"
CurrentDb.Execute strSQL, dbFailOnError
End If

End Sub
 
A

Allison

Thank you kindly. I'll go fiddle with that to make it work.

Allison

Douglas J. Steele said:
Best way is to use VBA.

Find the properties of the check box and look for the property associated
with the AfterUpdate event. Set the property to [Event Procedure], then
click on the ellipsis (...) to the right of the property. That will take you
into the VB Editor, in the middle of code that should look something like:

Private Sub NameOfCheckBox_AfterUpdate()

End Sub

Type the code between those two lines, so that you end up with something
like:

Private Sub NameOfCheckBox_AfterUpdate()

Dim strSQL As String

If Me!NameOfCheckBox Then
strSQL = "INSERT INTO MyTable (NumericField, TextField) " & _
"VALUES(" & Me!SomeNumericFieldOnForm & ", " _
"""" & Me!SomeTextFieldOnForm & """)"
CurrentDb.Execute strSQL, dbFailOnError
End If

End Sub



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Allison said:
Access 2003, Win XP

Is it possible to write a record to a table if a yes/no checkbox is ticked
by the user to yes on a form? The table I want to write to is not
attached
to the form (a query is attached to the form).

If it is possible, please point me in the right direction to code this.

Thank you.

Allison
 

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