Solved

How update field in an unbound table

Posted on 2011-09-12
5
373 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

623 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