Add vba in a table

lg5050

Registered User.
Local time
Today, 00:00
Joined
Nov 26, 2014
Messages
25
I have an table and i have a form. On the form i don't have a textbox and on the table i have a field called CAFlag. Is it possiable that i can make the table have an Y or N if CALine field on form is not null in vba. Please help.:confused:
 
Look into the MyForm (e.g. Home_2) - MyField's change event
Lets assume the table has a Primary Key ID of some type.
That will need to be assigned.

Get the PrimaryID. Create a Query for the table with the field that needs updating. Change the query design to an Update query where the primary key is the criteria and it changes your boolean field to true.
Look at the query design in the SQL mode. That will give you the template for the line 30 below

This code can go into the forms text field change event.

The nice thing about an Execute is that it runs fast and it is indendent.

Code:
        CurrentPKID = [Forms]![Home_2]![lst_PKey]
20        If not IsNull(MyFormField) Then ' logical statement
30            strUpdateSQL = "UPDATE MyTable SET MyTable.MyTableBooleanField = -1 WHERE (((MyTable.PKField)=" & CurrentPKID & " ));"
40           CurrentDb.Execute strUpdateSQL, dbSeeChanges
              ' The execute updates the field
50        End If
 

Users who are viewing this thread

Back
Top Bottom