Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 19th, 2006, 05:56 AM
Friend of Wrox
 
Join Date: Apr 2006
Posts: 159
Thanks: 0
Thanked 0 Times in 0 Posts
Default update a fields value

Hi,

just have another question. I tried to find the solution myself, but it does not work...

What I would like to do is: When I choose a value from a combo box, the value of a check box on the same form should remain 'No' or be changed to 'Yes' according to the value I choose in the combo box.

When the value 'onvolledig ingevuld' is chosen, the check box should remain on the 'No' value, when the value in the combo box is deleted (because the wrong record was chosen for exemple) the value should stay (or come back to) 'No' also. In every other scenario, the value of the combo box should be changed to 'Yes'

The code I'm using is:

Private Sub Nummer_code_AfterUpdate()
    On Error Resume Next
    Select Case Nummer_code.Value
        Case "Onvolledig ingevuld"
            TT_terug.Value = 0
        Case Isnull
            TT_terug.Value = 0
        Case Else
            TT_terug.Value = -1
    End Select
End Sub

where 'Nummer_code' is the combo box of course and the name of the check box is 'TT_terug'. What is wrong with this code? What should I do to make this work???

Thanks

 
Old May 19th, 2006, 06:39 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Hi,

   Me again.

   You need to put this code it two places, one on the after update event of the combo box, and the other on the On Current event of the form. Then I would suggest taking the value in the combo box as a variable instead of taking it right from the combo box in your select case statements.

Also, please make sure the combo box bound column is a string, as you indicate here. If it is a number, then you need to call Column(1).

Something like:

Private Sub Nummer_code_AfterUpdate()
    'On Error Resume Next remove this line

    Dim sValue As String

    If IsNull(Me.Nummer_code) Or Me.Nummer_code = "" Then
        Me.TT_terug = 0
        Else
        sValue = Me.Nummer_code.Column(1)
        If sValue = "Onvolledig ingevuld" Then
           TT_terug = 0
           Else
           TT_terug = -1
        End If
    End If
End Sub


Anywho, if you are only using the check box as an automated control, there is not really a need for it since this check can be done in subsequent queries. If you must have the check box on the form, and it is only to be used when it is automated, be sure to set it to Enabled = No, Locked = Yes.

Did that help?


mmcdonal
 
Old May 19th, 2006, 06:41 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Sorry, in the second nested conditional, it should have been:

       If sValue = "Onvolledig ingevuld" Then
           Me.TT_terug = 0
           Else
           Me.TT_terug = -1
        End If


mmcdonal





Similar Threads
Thread Thread Starter Forum Replies Last Post
Update Table fields karajian Access VBA 2 December 7th, 2004 03:48 PM
Problem to update fields cilla Classic ASP Databases 22 October 26th, 2004 07:36 AM
Update multiple fields. slgknjn Classic ASP Databases 6 February 15th, 2004 10:26 AM
fields from tables to update damnnono_86 Access 3 November 5th, 2003 04:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.