[AccessD] Multiple Unbound Text Boxes After Update Event - ADD ON QUESTION

ACTEBS actebs at actebs.com.au
Tue Feb 4 20:04:57 CST 2014


Hi John,

The way I did it was like this thanks to Shamil and Dan:

I used the Tag property of each of the text boxes I wanted the code to
manage, in my case I set it to True. Then I created a table with the
following fields:

FieldID > Autonumber Primary Key
JobDetailID  > JobDetailID this data relates to
FieldName > Actual field Name that was being recorded from the form
FieldValue > The value being recorded from the field

To save having to manage changes/edits on the users part, I just delete all
the old data relating to that Job and recreate it with whatever is there
now. The method used to save the data is as follows:

Private Sub SaveFibreData()
    Dim strSQL As String
    Dim rst As DAO.Recordset
    Dim dbs As DAO.Database
    Dim ctl As Control
    
    strSQL = "select * from tblJobFibresField where JobDetailID = " &
Nz(Me.JobDetailID, 0)
    
    Set dbs = OpenDatabase(BELocation)
    Set rst = dbs.OpenRecordset(strSQL, dbOpenDynaset)
    
    If rst.RecordCount > 0 Then
        rst.MoveFirst
        Do Until rst.EOF
            With rst
                .Delete
            End With
        rst.MoveNext
        Loop
    End If
    
    For Each ctl In Me.Controls
        If ctl.ControlType = acTextBox Then
            If ctl.Tag = "True" Then
                If Nz(ctl, 0) <> 0 Then
                    With rst
                        .AddNew
                        !JobDetailID = Nz(Me.JobDetailID, 0)
                        !FieldName = ctl.Name
                        !FieldValue = ctl.Value
                        .Update
                    End With
                End If
            End If
        End If
    Next ctl
      
    rst.Close
    Set rst = Nothing
    dbs.Close
    Set dbs = Nothing
End Sub

This how I return the values to the field when user want to edit that data:

Private Sub GetJobFibreFieldValues()
    Dim strSQL As String
    Dim rst As DAO.Recordset
    Dim dbs As DAO.Database
    Dim ctl As Control
    
    strSQL = "select * from tblJobFibresField where JobDetailID = " &
Nz(Me.JobDetailID, 0)
    
    Set dbs = OpenDatabase(BELocation)
    Set rst = dbs.OpenRecordset(strSQL, dbOpenDynaset)
     
    For Each ctl In Me.Controls
        If ctl.ControlType = acTextBox Then
            If ctl.Tag = "True" Then
                If rst.RecordCount > 0 Then
                    rst.MoveFirst
                    Do Until rst.EOF
                        With rst
                            If ctl.Name = rst!FieldName Then
                                ctl = !FieldValue
                            End If
                        End With
                    rst.MoveNext
                    Loop
                End If
            End If
        End If
    Next ctl
      
    rst.Close
    Set rst = Nothing
    dbs.Close
    Set dbs = Nothing    

End Sub

Hope that helps...

Vlad

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of John Clark
Sent: Wednesday, 5 February 2014 1:23 AM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Multiple Unbound Text Boxes After Update Event - ADD
ON QUESTION

I feel like I'm missing something though Arthur...what command/code do I
use? I'm thinking along the lines of a WITH statement, but that won't
exactly do it, if I'm thinking correctly. 

>>> Arthur Fuller <fuller.artful at gmail.com> 2/4/2014 9:15 AM >>>
Probably you want one of the groups to be visible by default. First of all,
give all the controls within each group a similar name, such as
grp1TextBox1. That will simplify handling them. Then make all the grp2
agrp3 controls invisible. After that it's simple to handle them in your
AfterUpdate event.

HTH,
Arthur


On Tue, Feb 4, 2014 at 8:53 AM, John Clark
<John.Clark at niagaracounty.com>wrote:

> I was actually going to ask a similar question this morning...
>
> I have essentially 3 groups of questions, and I'd like to present one 
> of these groups, based on the value of another field. And, I was 
> wondering if I could group them and do it that way. I was even 
> thinking about giving the fields a certain naming convention to do this...
>
> So, it is good to know it can be done. BUT...I'm still a bit shaky (to 
> say the least) on how to carry this off.
>

Notice: This electronic transmission is intended for the sole use of the
individual or entity to which it is addressed and may contain confidential,
privileged or otherwise legally protected information. If you are not the
intended recipient, or if you believe you are not the intended recipient,
you are hereby notified that any use, disclosure, copying, distribution, or
the taking of any action in reliance on the contents of this information, is
strictly prohibited. Niagara County is not responsible for the content of
any external hyperlink referenced in this email or any email. 
IF YOU HAVE RECEIVED THIS TRANSMISSION IN ERROR, PLEASE NOTIFY THE SENDER
IMMEDIATELY BY EMAIL AND DELETE THE ORIGINAL MESSAGE ALONG WITH ANY PAPER OR
ELECTRONIC COPIES. 
Thank you for your cooperation.








More information about the AccessD mailing list