Results 1 to 10 of 10
  1. #1
    Zombai is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2017
    Posts
    24

    No Current Record

    I'm quite bamboozled.


    Recently i attempted to revisit a project a started a few months ago. When testing all of my forms again, i get to this one in particular, which fails to create the new record i require it to.

    Below i have a screenshot of the form & error, as well as my coding for the entire form.

    I opened this project on a computer that i did not originally create the database on, however i have never had any issues prior with opening this project on different machines.

    It may be also worth noting that i recently recreated a couple of tables, however i renamed them exactly the same way, and set the relationships up correctly again.
    Unfortunately i did not test this form prior to recreating tables. The table this form uses specifically, was not recreated.

    Any assistance would be greatly appreciated.
    Click image for larger version. 

Name:	error.PNG 
Views:	17 
Size:	29.4 KB 
ID:	34042

    Code:
    Option Compare DatabaseOption Explicit
    
    
    Private Sub Form_Load()
          DoCmd.GoToRecord , "", acNewRec
    End Sub
    
    
    Private Sub btnClear_Click()
    Me.Undo
    End Sub
    
    
    Private Sub cboAccountName_AfterUpdate()
        Dim SCustomerSource As String
        Dim SVehicleSource As String
            
        SCustomerSource = "SELECT [Customers].[Customer ID]," & _
                        " [Customers].[First Name], " & _
                        " [Customers].[Last Name], " & _
                        " [Customers].[Mobile Number], " & _
                        " [Customers].[Landline], " & _
                        " [Customers].[Fax], " & _
                        " [Customers].[Email Address] " & _
                            "From Customers " & _
                            "WHERE [Account Number] = " & Me.cboAccountName.Value
                            
        SVehicleSource = "SELECT [Vehicles].[Vehicle Number]," & _
                        " [Vehicles].[Vehicle Make], " & _
                        " [Vehicles].[Vehicle Model], " & _
                        " [Vehicles].[Rego], " & _
                        " [Vehicles].[Build Date], " & _
                        " [Vehicles].[VIN], " & _
                        " [Vehicles].[Required Repairs] " & _
                            "From Vehicles " & _
                            "WHERE [Account Number] = " & Me.cboAccountName.Value
                                                
    
    
        Me.cboCustomerName.RowSource = SCustomerSource
        Me.cboCustomerName.Requery
        Me.cboVehicle.RowSource = SVehicleSource
        Me.cboVehicle.Requery
    End Sub
    
    
    Private Sub cboCustomerName_AfterUpdate()
    Me.stFirstName = Me.cboCustomerName.Column(1)
    Me.stLastName = Me.cboCustomerName.Column(2)
    Me.stMobilephone = Me.cboCustomerName.Column(3)
    Me.stLandLine = Me.cboCustomerName.Column(4)
    Me.stFax = Me.cboCustomerName.Column(5)
    Me.stEmailAddress = Me.cboCustomerName.Column(6)
        End Sub
        
    Private Sub cboVehicle_AfterUpdate()
    Me.stVehicleMake = Me.cboVehicle.Column(1)
    Me.stVehicleModel = Me.cboVehicle.Column(2)
    Me.stRego = Me.cboVehicle.Column(3)
    Me.stBuildDate = Me.cboVehicle.Column(4)
    Me.stVIN = Me.cboVehicle.Column(5)
    Me.stRequiredRepairs = Me.cboVehicle.Column(6)
    End Sub
    '------------------------------------------------------------
    ' btnExit_Click
    '
    '------------------------------------------------------------
    Private Sub btnExit_Click()
    On Error GoTo btnExit_Click_Err
    
    
        DoCmd.Close , ""
    
    
    
    
    btnExit_Click_Exit:
        Exit Sub
    
    
    btnExit_Click_Err:
        MsgBox Error$
        Resume btnExit_Click_Exit
    
    
    End Sub
    
    
    
    
    '------------------------------------------------------------
    ' btnSubmit_Click
    '
    '------------------------------------------------------------
    Private Sub btnSubmit_Click()
    On Error GoTo btnSubmit_Click_Err
        
           If IsNull(Me.cboAccountName) Or Me.cboAccountName = "" Then
            MsgBox "Please select an account.", vbOKOnly, "Required Information"
                Me.cboAccountName.SetFocus
            Exit Sub
        End If
        
        If IsNull(Me.cboCustomerName) Or Me.cboCustomerName = "" Then
            MsgBox "Please select a customer.", vbOKOnly, "Required Information"
                Me.cboCustomerName.SetFocus
            Exit Sub
        End If
        
        If IsNull(Me.cboVehicle) Or Me.cboVehicle = "" Then
            MsgBox "Please select a Vehicle.", vbOKOnly, "Required Information"
                Me.cboVehicle.SetFocus
            Exit Sub
        End If
        
        If IsNull(Me.stBookingDate) Or Me.stBookingDate = "" Then
            MsgBox "You need to insert a booking date!", vbOKOnly, "Required Information"
                Me.stBookingDate.SetFocus
                Exit Sub
        End If
    
    
        
        DoCmd.RunCommand acCmdSaveRecord
        If (MacroError <> 0) Then
            Beep
            MsgBox MacroError.Description, vbOKOnly, ""
        End If
    
    
    
    
    btnSubmit_Click_Exit:
        Exit Sub
    
    
    btnSubmit_Click_Err:
        MsgBox Error$
        Resume btnSubmit_Click_Exit
    
    
    End Sub
    
    
    
    
    Private Sub Form_BeforeUpdate(Cancel As Integer)
       If Me.Dirty = True Then
    Cancel = True
    Me.Undo
    End If
    End Sub

  2. #2
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    Which button is causing the error - comment out the error handling to see where it is happening ?
    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 ↓↓

  3. #3
    Zombai is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2017
    Posts
    24
    The error occurs when i press the 'Submit' button - I should have specified that, sorry.

    I commented out the error handling, and get the run-time error 3021 'no current record'

  4. #4
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    Which bit of code does it highlight ?
    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 ↓↓

  5. #5
    Zombai is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2017
    Posts
    24
    It doesn't highlight any code

  6. #6
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    I think it's because your Form Before update event is where you should be doing all that validation, otherwise the record is already saved.
    At the moment you appear to be cancelling all the inputs, at all times if the record has changed - which would explain the error ?
    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 ↓↓

  7. #7
    Zombai is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2017
    Posts
    24
    I get an error when i try to use "DoCmd.GoToRecord , "", acNewRec" in the Before Update event.

    This exact code worked on a different machine, and as far as i can tell is all coded correctly.
    I seriously don't understand why it's not creating new records

  8. #8
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    Sorry we have crossed purposes here; I wasn't suggesting you move the whole code in to the before update event, just the bit that checks for the various fields having data;

    Code:
       If IsNull(Me.cboAccountName) Or Me.cboAccountName = "" Then        MsgBox "Please select an account.", vbOKOnly, "Required Information"
                Me.cboAccountName.SetFocus
            Exit Sub
        End If
        
        If IsNull(Me.cboCustomerName) Or Me.cboCustomerName = "" Then
            MsgBox "Please select a customer.", vbOKOnly, "Required Information"
                Me.cboCustomerName.SetFocus
            Exit Sub
        End If
        
        If IsNull(Me.cboVehicle) Or Me.cboVehicle = "" Then
            MsgBox "Please select a Vehicle.", vbOKOnly, "Required Information"
                Me.cboVehicle.SetFocus
            Exit Sub
        End If
        
        If IsNull(Me.stBookingDate) Or Me.stBookingDate = "" Then
            MsgBox "You need to insert a booking date!", vbOKOnly, "Required Information"
                Me.stBookingDate.SetFocus
                Exit Sub
        End If
    But it's not quite that simple, as you would need to restructure the way that code exits the sub. It would need to issue Cancel = True before the exit sub, and would keep doing it until all the fields were completed, which isn't very user friendly.

    Normally you would create a small error string containing what was missing, then present that as one single msgbox at the end of the checking then cancel the save, and let them retry.
    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 ↓↓

  9. #9
    Zombai is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2017
    Posts
    24
    The validation stuff all works fine where it is.
    Even if i did move it, i can't see how that would resolve the issue of not creating the record

  10. #10
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    It's because when you go to save the record you have already cancelled it or saved it due to this code operating before any updates are saved;

    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
       If Me.Dirty = True Then
    Cancel = True
    Me.Undo
    End If
    End Sub
    Do you understand what this is doing?
    If not I would comment it out, and see what happens.

    If you get stuck post up a stripped down zipped copy of the database with the minimum forms / tables required to replicate the issue.
    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 ↓↓

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

Similar Threads

  1. Replies: 7
    Last Post: 01-04-2018, 06:35 PM
  2. Replies: 8
    Last Post: 07-23-2017, 02:04 PM
  3. Replies: 3
    Last Post: 02-06-2015, 01:18 PM
  4. Replies: 16
    Last Post: 02-06-2013, 03:06 PM
  5. Replies: 3
    Last Post: 09-19-2012, 07:34 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