Add to table

  • Thread starter Thread starter Allison
  • Start date Start date
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
 
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
 
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
 
Back
Top