Page 1 of 2 12 LastLast
Results 1 to 15 of 29
  1. #1
    ShaunG is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jan 2018
    Posts
    237

    code not working in bound controls on one form, but is working properly on another form

    Im using the codes below to populate fields automatically when a user logs in from a combo box for certain reasons... im inserting them in the default value properties in design mode when needed

    =[Forms]![LoginForm]![cboUser].[Column](1) - users name when they make a record

    =Date() - the date when they made the record

    both work fine in the bound controls on another form, it also works with any unbound text boxes.



    im having issues with another form neither of these 2 codes are giving me results, yet I put the codes in unbound text boxes on the same form and results appear.

    anyone had this before or have any ideas?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    What does happen - error message, wrong results, nothing?

    Are you able to manually edit the record?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ShaunG is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jan 2018
    Posts
    237
    Quote Originally Posted by June7 View Post
    What does happen - error message, wrong results, nothing?

    Are you able to manually edit the record?
    record shows up blank.... when I erase the control source, the value of the date or the user name shows up, if I erase both control source's they both show up how supposed to.

    yeah I can access the fields eitherway

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    No idea. If you want to provide db for analysis, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    ShaunG is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jan 2018
    Posts
    237
    Quote Originally Posted by June7 View Post
    No idea. If you want to provide db for analysis, follow instructions at bottom of my post.
    yeah no worries, cool ill upload the database

  6. #6
    ShaunG is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jan 2018
    Posts
    237
    cabtech1.zip


    first initial of first name is password,

    after login, its in the received goods entry button and then double click on the hyperlink order number to bring entry page up.

    fyi if you click the order complete button it locks that particular record.

  7. #7
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Default values only apply to new records. The record you are opening the form to already exists, so the defaults don't apply.

    You need to set the values on form load - but only if they are null. Something like
    Code:
    Private Sub Form_Load()
        
        If IsNull(Me.DateReceived) Then Me.DateReceived = Now()
        
        If IsNull(Me.ReceivedBy) Then Me.ReceivedBy = [Forms]![LoginForm]![cboUser].[Column](1)
        
        
    End Sub
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  8. #8
    ShaunG is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jan 2018
    Posts
    237
    Quote Originally Posted by Minty View Post
    Default values only apply to new records. The record you are opening the form to already exists, so the defaults don't apply.

    You need to set the values on form load - but only if they are null. Something like
    Code:
    Private Sub Form_Load()
        
        If IsNull(Me.DateReceived) Then Me.DateReceived = Now()
        
        If IsNull(Me.ReceivedBy) Then Me.ReceivedBy = [Forms]![LoginForm]![cboUser].[Column](1)
        
        
    End Sub
    That does make sense Minty... the code works for the date side of things but I get a run time error 450 - wrong number of arguments or invalid property assignment

    im using the code in lost focus of the qtyRecieved so that way if someone opens that item up by mistake it wont record anything unless they move to it.

    Private Sub txtQtyReceived_LostFocus()
    If IsNull(Me.DateReceived) Then Me.txtDateReceived = Date

    If IsNull(Me.ReceivedBy) Then Me.txtReceivedBy = [Forms]![LoginForm]![cboUser].[Column](1)
    End Sub


    it is highlighting this section - Me.ReceivedBy = [Forms]![LoginForm]![cboUser].[Column](1)

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Is LoginForm still open?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    ShaunG is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jan 2018
    Posts
    237
    Quote Originally Posted by June7 View Post
    Is LoginForm still open?
    that's correct it is


    I logged in and closed it then got a run time error 2450 could find login in form

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    You should run Debug > Compile. There will be several referencing errors. Very annoying when trying to debug issue.

    ReceivedBy field in tblOrderDetails is text type. Shouldn't you be saving the EmployeesID_PK which is a number type instead of their UserName?

    The following works:

    Private Sub txtQtyReceived_LostFocus()
    If IsNull(Me!DateReceived) Then Me.txtDateReceived = Date
    If IsNull(Me!ReceivedBy) Then Me.txtReceivedBy = Form_LoginForm.cboUser.Column(1)
    End Sub
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #12
    ShaunG is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jan 2018
    Posts
    237
    Quote Originally Posted by June7 View Post
    You should run Debug > Compile. There will be several referencing errors. Very annoying when trying to debug issue.

    ReceivedBy field in tblOrderDetails is text type. Shouldn't you be saving the EmployeesID_PK which is a number type instead of their UserName?

    The following works:

    Private Sub txtQtyReceived_LostFocus()
    If IsNull(Me!DateReceived) Then Me.txtDateReceived = Date
    If IsNull(Me!ReceivedBy) Then Me.txtReceivedBy = Form_LoginForm.cboUser.Column(1)
    End Sub
    sorry about that... Im learning as Im going, I wasn't aware of Debug > Compile ill try my best to workout out the issues

    it was saving the EmployeeID_PK to begin with, but If remember correctly the combo box was referencing a number as well so I rearranged it... should I change it?

    thanks for the code.

  13. #13
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    In keeping with data normalization and relational db principles, should save the ID instead of duplicating the UserName into another table. However, you want to display the UserName.

    Change ReceivedBy field data type to number.

    Change code to:
    If IsNull(Me!ReceivedBy) Then Me!ReceivedBy = Form_LoginForm.cboUser

    Then either:
    1. Make the textbox on GoodsEntry a combobox (or a very short listbox)
    or
    2. Change the GoodsEntry RecordSource to include the Employees table and bind textbox to the UserName field and set Locked property to Yes
    Last edited by June7; 01-24-2018 at 12:29 PM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  14. #14
    ShaunG is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jan 2018
    Posts
    237
    Quote Originally Posted by June7 View Post
    In keeping with data normalization and relational db principles, should save the ID instead duplicating the UserName into another table. However, you want to display the UserName.

    Change ReceivedBy field data type to number.

    Change code to:
    If IsNull(Me!ReceivedBy) Then Me!ReceivedBy = Form_LoginForm.cboUser

    Then either:
    1. Make the textbox on GoodsEntry a combobox (or a very short listbox)
    or
    2. Change the GoodsEntry RecordSource to include the Employees table and bind textbox to the UserName field and set Locked property to Yes
    trying my best to keep the database normalized and principles in check, so ill change it and ill try work out your option 2 sounds good, thanks.

  15. #15
    ShaunG is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jan 2018
    Posts
    237
    Quote Originally Posted by June7 View Post
    In keeping with data normalization and relational db principles, should save the ID instead duplicating the UserName into another table. However, you want to display the UserName.

    Change ReceivedBy field data type to number.

    Change code to:
    If IsNull(Me!ReceivedBy) Then Me!ReceivedBy = Form_LoginForm.cboUser

    Then either:
    1. Make the textbox on GoodsEntry a combobox (or a very short listbox)
    or
    2. Change the GoodsEntry RecordSource to include the Employees table and bind textbox to the UserName field and set Locked property to Yes
    don't think im doing this correctly I changed the GoodsEntry record source to tblEmployees and set ReceivedBy to Control source =[tblEmployees]![UserName]

    do I need to change any thing with the combo box itself?

    the GoodsEntry Form boxes have #Name? in them also when I try open the form get compile error which I think relates to

    Private Sub Form_Current()
    If Me.OrderComplete = True Then
    [Forms]![GoodsEntry]![txtProduct].Enabled = False
    [Forms]![GoodsEntry]![txtDateReceived].Enabled = False
    [Forms]![GoodsEntry]![txtQtyReceived].Enabled = False
    [Forms]![GoodsEntry]![txtReceivedBy].Enabled = False
    [Forms]![GoodsEntry]![txtOrderComplete].Enabled = False
    End If
    End Sub

    this is to lock out the controls once order is complete.

    If I don't change the record source of the form to tblEmployees the ReceivedBy shows EmployeeID_Pk number

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 10-12-2015, 12:16 PM
  2. INSERT INTO code not working properly.
    By Alphix in forum Forms
    Replies: 8
    Last Post: 11-12-2014, 04:10 PM
  3. Login form not working properly
    By papa yaw in forum Forms
    Replies: 2
    Last Post: 12-22-2012, 09:46 AM
  4. Login form is not working properly
    By papa yaw in forum Forms
    Replies: 1
    Last Post: 12-19-2012, 05:25 PM
  5. Msgbox And Search Code Not Working Properly
    By vampyr07au in forum Forms
    Replies: 1
    Last Post: 05-02-2011, 05:16 PM

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