Solved

How update field in an unbound table

Posted on 2011-09-12
5
319 Views
Last Modified: 2013-11-05
I have a form with a text box and a checkbox.  The form is unbound.  The textbox is named "txtJobN" and the checkbox is named "chkbxUrgent".  The user first enters a number in the "txtJobN" field.  Then they either check or uncheck the checkbox.  When they check or uncheck the checkbox I want the onclick event of the checkbox to update a record in tblJob where the key field equals the value in "txtJobN".

How?
0
Comment
Question by:SteveL13
  • 3
5 Comments
 
LVL 31

Accepted Solution

by:
Helen_Feddema earned 125 total points
ID: 36523644
First, I would recommend changing txtJobN to a combo box, with a row source of valid Job numbers.  This will avoid frustration for the users.  Then run this code from the checkbox's AfterUpdate event (I am assuming that you want the update to occur only when the checkbox is checked).  Of course, you will need to add code to to the actual updating, as indidated in the code.
Private Sub chkUrgent_AfterUpdate()

   Dim strJobNo As String
   Dim rst As DAO.Recordset
   Dim strSearch As String
   
   If Me![chkUrgent].Value = True Then
      strJobNo = Nz(Me![txtJobNo].Value)
      
      If strJobNo <> "" Then
         Set rst = CurrentDb.OpenRecordset("tblJobs", dbOpenDynaset)
         strSearch = "[JobNo] = " & Chr(39) & strJobNo & Chr(39)
         rst.FindFirst strSearch
         If rst.NoMatch = False Then
            rst.Edit
            'Your update code here
            rst.Update
         End If
      End If
   End If
   
End Sub

Open in new window

0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 36523665
For the updating code, you need a field name, and a value to assign to it.  You may need to add more controls to your form to get this information.
0
 

Author Comment

by:SteveL13
ID: 36523812
Ok.  I have changed the field to a combobox.  When the user selects a record from the list I still need to update that record's "Urgent" field as true or false depending on what the user did with the checkbox which is named "chkbxUrgent".  I am not sure how to accomplish this.
0
 
LVL 26

Assisted Solution

by:Nick67
Nick67 earned 125 total points
ID: 36525592
You aren't sure about this part?

         If rst.NoMatch = False Then
            rst.Edit
            'Your update code here
            rst.Update
         End If

it would be
    rst!WhateverFieldYouWantChanged = Me.chkUrgent.Value

         If rst.NoMatch = False Then
            rst.Edit
            rst!WhateverFieldYouWantChanged = Me.chkUrgent.Value
            rst.Update
         End If
0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 36530948
If Nick's comment is correct, then you need to remove the portion of my original code that proceeds only if the checkbox has a True value.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now