Solved

How update field in an unbound table

Posted on 2011-09-12
5
356 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

839 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