Results 1 to 10 of 10
  1. #1
    isnpms is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2010
    Posts
    19

    Query and populate fields

    I have a system with 2 tables (tblMain, tblSec) and one form and one subform.


    The tblMain has main data at the main form (fCod (key), fName, fAddress, fPhone, etc.) and the tblSec has some specific data that can repeat sometimes, others no (fCod, fName -pick name data from main form - fPaymantValue, fDate, fBank, etc.) for each work that each person can do, many times.
    I’m working a way for when I add a new register at the subform for an specific person and the data at the fields at the tblSec for the same name won’t change, I’d not need to write them again and these fields would populate automatically.
    I have build the following query that make this work: qryDayWork
    =========================
    SELECT tblSec.fName, tblSec.fPaymant, tblSec.Bank, tblSec.Agency, tblSec.CashCount, tblSec.CPF, tblSec Main.RG
    FROM tblSec
    WHERE (((tbl tblSec.fName)=[Forms]![frmMain]![Name]) AND ((tblSec.fPaymant) Is Not Null) AND ((tblSec.Bank) Is Not Null) AND ((tblSec.Agency) Is Not Null) AND ((tblSec.CashCount) Is Not Null) AND ((tblSec.CPF) Is Not Null) AND ((tblSec.RG) Is Not Null));
    =========================
    What I need and I have no idea is how to write a code for populate these fields at subfomr when still there is a register of them (at tblSec) for that person and preferentially the last data added. It would have to check if there is any data previously added or not, inform that (msgbox) and populate them with the Query results.
    Anyone could help me?
    Thanks a lot.
    Ivan Sinigaglia (Brasil)

  2. #2
    isnpms is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2010
    Posts
    19
    I have tried the following but also didin't work (for exemple, cboBank (fBank field).
    ============================================
    Private Sub cboBank_AfterUpdate()
    Form_frmSec.Filter = "SELECT * FROM tblSec WHERE fBank='" & cboBank.Value & "';"
    Form_frmSec.FilterOn = True
    End Sub
    ============================================

  3. #3
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    You don't need full query when you set the form filter.

    Private Sub cboBank_AfterUpdate()
    Form_frmSec.Filter = "fBank='" & cboBank.Value & "'"
    Form_frmSec.FilterOn = True
    End Sub

  4. #4
    isnpms is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2010
    Posts
    19
    I think my answer is bad done.
    When i click ADD button at the subform and there is a previous register, i need only some fields keep these data for adding a new register with others i will type.
    And with AfterUpdate() it is not working.
    Is there any working way for this?
    Thanks
    Last edited by isnpms; 08-27-2010 at 02:32 PM. Reason: adding more

  5. #5
    isnpms is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2010
    Posts
    19
    I am trying this (other forum sugestion):

    Private Sub YourTextControlName_AfterUpdate()
    If Not IsNull(Me.YourTextControlName.Value)
    YourTextControlName.DefaultValue = """" & Me.YourTextControlName.Value & """"
    End If
    End Sub

    But after i click ADD button every fields turn blank, waiting for insert data. Didn't keep the previous value of the field.

  6. #6
    pkstormy's Avatar
    pkstormy is offline Access/SQL Server Expert
    Windows XP Access 2003
    Join Date
    Mar 2010
    Location
    Madison
    Posts
    682
    To set the default value, try:

    Private Sub YourTextControlName_AfterUpdate()
    refresh
    If Not IsNull(Me.YourTextControlName.Value) then
    me.YourTextControlName.DefaultValue = "=" & Me.YourTextControlName.Value & ""
    End If
    End Sub

    or

    Private Sub YourTextControlName_AfterUpdate()
    refresh
    If Not IsNull(Me.YourTextControlName.Value) then
    me.YourTextControlName.DefaultValue = "= ' " & Me.YourTextControlName.Value & " ' "
    End If
    End Sub

    or see here: https://www.accessforums.net/code-re...html#post29558

  7. #7
    isnpms is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2010
    Posts
    19
    Nothing. The same blank field

  8. #8
    pkstormy's Avatar
    pkstormy is offline Access/SQL Server Expert
    Windows XP Access 2003
    Join Date
    Mar 2010
    Location
    Madison
    Posts
    682
    Try the example in the link. It worked for me (I created and tested it).

  9. #9
    isnpms is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2010
    Posts
    19
    Hi pkstormy,
    I really appreciate your help, but it’s not working.
    I will tell you step-by-step with your example what’s going on here at Ms Access 2010 with these function.
    Fig 01: I’ve just added two command buttons: ADD and SAVE (I know that wasn’t really necessary. I will explain why I did this later).


    Fig 02: When I click ADD button or the last arrow to the right (adding too), they turn all blank and the NEW (Novo) at CustomerID field appear.




    Fig 03: This is a simulation (photoshop) only to show you what I need. If I’m at an specific register (anyone, number 3, 2, etc) and i click add, I would like the fields with AFTERUPDATE code repeat these data to the next NEW register.

    Maybe it’s this version MS Access 2010 that’s not working. I don't know.
    Nevertheless i thank you very much and i will keep trying.
    Any idea, if possible, tell me.
    Thank you again.

  10. #10
    isnpms is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2010
    Posts
    19
    There is no possible solution for this at my rookie level.
    I’m not a programmer, I’m a beginner enthusiast, but I’m relay tired of all this.
    I’ll assign this forum as solved and give up this work.
    Thank you all for your help.
    Bye.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Using random fields in Excel to populate Access table
    By cryswater in forum Import/Export Data
    Replies: 3
    Last Post: 05-14-2013, 02:50 PM
  2. auto populate mutiple fields
    By jomoan58 in forum Access
    Replies: 1
    Last Post: 07-23-2010, 01:03 PM
  3. using a combo box to populate fields then save
    By crazy1701d in forum Forms
    Replies: 2
    Last Post: 05-19-2010, 07:22 PM
  4. Populate one field based upon another fields data
    By BigBrownBear in forum Queries
    Replies: 1
    Last Post: 03-23-2010, 04:27 PM
  5. Auto populate fields on a form
    By ldarley in forum Forms
    Replies: 0
    Last Post: 08-14-2008, 09:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums