Results 1 to 2 of 2
  1. #1
    donsi is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Sep 2016
    Posts
    16

    Error on updating field in form

    Form has textbox where users enter customer's account number to log transaction. DLookup function will look into tblcustomers for matching account number and return FN and LN if found. Now problem is when user enters incorrect number and want to change it or want to change customer account number after entering it first time (moved to next textbox field) access doesn't let them change the account number field without saving the record. Error is : "To make changes to this field, first save the record"



    VBA for DLookup:
    Code:
    Private Sub TxtFirstName_GotFocus()
    Dim varX As String
    Dim varY As String
    On Error GoTo Problem
    varX = DLookup("Last_Name", "TblCustomer", "Cust_Card_No = " & [Forms]![FrmGroupLog]![Cust_Card_No])
    Me.TxtFirstName = varX
    varY = DLookup("First_Name", "TblCustomer", "Cust_Card_No = " & [Forms]![FrmGroupLog]![Cust_Card_No])
    Me.TxtLastName = varY
    Exit Sub
    Problem:
    If Err.Number = 94 Then
    Me.TxtFirstName = " "
    Me.TxtLastName = " "
    MsgBox "Please Enter guest Name"
    End If
    End Sub

  2. #2
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    I think your code is in the wrong place. Try putting it in the After Update event of the [Cust_card_No] textbox, and you don't want the user to change first or last name anyway - it's already in tblCustomer.

    Also, you might want to re-think your logic. If a user enters an invalid (i.e. it doesn't exist) customer ID, then you don't want to allow them to proceed further without first entering a new customer record into TblCustomer (or correcting the one they entered).

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

Similar Threads

  1. updating a field on a form
    By George in forum Modules
    Replies: 7
    Last Post: 04-22-2016, 08:42 PM
  2. Replies: 7
    Last Post: 03-02-2014, 08:47 PM
  3. Updating date field in access from excel causes error
    By madamson86 in forum Programming
    Replies: 2
    Last Post: 12-14-2011, 02:38 AM
  4. Help Updating Form Field
    By emarchant in forum Access
    Replies: 3
    Last Post: 10-08-2010, 11:07 AM
  5. Updating Table field from Form
    By Kunuk in forum Access
    Replies: 0
    Last Post: 02-26-2009, 11:41 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