Results 1 to 2 of 2
  1. #1
    RaMcHiP is offline Novice
    Windows Vista Access 2007
    Join Date
    May 2009
    Posts
    4

    Issues with DoCmd.GoToControl

    Hi there everyone, I am fairly new to access this is my first major project and am running into problems with a sub that I am using... here are the symptoms if I open up and older version of my DB and cut and paste this sub into it, it works for a little while and then after either shutting it down and restarting or just a random amount of time it stops working and gives me the error

    Run-Time Error '2109':

    There is no field named 'CAB' in the current record.

    I am unsure of why it is doing this obviously I am not changing anything in my tables so the field is still there.. here is my code I appreciate anyones help on this matter...



    Code:
    Private Sub CAB_KeyDown(KeyCode As Integer, Shift As Integer)
    Dim strNewCAB As String
    Dim strOldCAB As String
        
        If EditCAB = False Then
            strOldCAB = CAB.Value
            
            If MsgBox("Are You Sure You Would Like To Change This Cab number?", _
                      vbYesNo + vbQuestion + vbDefaultButton2, _
                      "Please Confirm:") = vbYes Then
                Me!CAB.Locked = False
                EditCAB = True
                strNewCAB = InputBox("What is the new cab number?", "New Cab number")
                    
                    If strNewCAB = "" Or strNewCAB = Empty Then
                        MsgBox "No Input Provided", vbInformation, "Required Data"
                        CAB.Value = strOldCAB
                        Me!CAB.Locked = True
                        EditCAB = False
                        DoCmd.RunCommand acCmdSaveRecord
                        CAB.SetFocus
                        Exit Sub
                    End If
                    
                    If strNewCAB < 1000 Then
                        Dim strSearch As String
                            DoCmd.ShowAllRecords
                            DoCmd.GoToControl ("CAB")
                            DoCmd.FindRecord strNewCAB
                            CAB.SetFocus
                            strSearch = CAB.Text
                                
                                If strSearch = strNewCAB Then
                                    DoCmd.ShowAllRecords
                                    DoCmd.GoToControl ("CAB")
                                    DoCmd.FindRecord strOldCAB
                                    CAB.SetFocus
                                    MsgBox "" & strSearch & " Is Taken - Please Try Again.", _
                                           , "Important Information"
                                    Exit Sub
                                Else
                                    CAB.SetFocus
                                    txtoldcab.Visible = True
                                    txtoldcab.SetFocus
                                    txtoldcab.Locked = False
                                    txtoldcab.Value = strOldCAB
                                    txtoldcab.Locked = True
                                    CAB.SetFocus
                                    txtoldcab.Visible = False
                                    CAB.Value = strNewCAB
                                    CAB.Locked = True
                                    EditCAB = False
                                    DoCmd.RunCommand acCmdSaveRecord
                                    MsgBox "Cab #" & strOldCAB & " Has Been Changed To Cab #" & strNewCAB & "", _
                                           , "Important Information"
                                End If
                    Else
                        MsgBox "Sorry, This Cab Number Is Incorrect", _
                        vbOKOnly, "Important Information"
                        CAB.Value = strOldCAB
                        Me!CAB.Locked = True
                        EditCAB = False
                        DoCmd.RunCommand acCmdSaveRecord
                        CAB.SetFocus
                        Exit Sub
                    End If
            Else
                CAB.SetFocus
                CAB.Value = strOldCAB
                Me!CAB.Locked = True
                EditCAB = False
            End If
            
        End If
    End Sub

  2. #2
    RaMcHiP is offline Novice
    Windows Vista Access 2007
    Join Date
    May 2009
    Posts
    4

    Problem Solved

    I fixed the problem by adding Me.Requery into the right places of my code and it works fine now because it TOTALLY refreshes the base file...

    here is the new code.....

    Code:
    Private Sub CAB_KeyDown(KeyCode As Integer, Shift As Integer)
    Dim strNewCAB As String
    Dim strOldCAB As String
    Dim strSearch As String
        
        If EditCAB = False Then
            If MsgBox("Are You Sure You Would Like To Change This Cab number?", _
                      vbYesNo + vbQuestion + vbDefaultButton2, _
                      "Please Confirm:") = vbYes Then
                strOldCAB = CAB.Value
            EditCAB = True
                strNewCAB = InputBox("What is the new cab number?", "New Cab number")
                    
                    If strNewCAB = "" Or strNewCAB = Empty Then
                        MsgBox "No Input Provided", vbInformation, "Required Data"
                        EditCAB = False
                        CAB.SetFocus
                        Me.Refresh
                        Exit Sub
                    End If
                    
                    If strNewCAB > 999 Then
                        MsgBox "Sorry, This Cab Number Is Incorrect", _
                        vbOKOnly, "Important Information"
                        EditCAB = False
                        CAB.SetFocus
                        Me.Refresh
                        Exit Sub
                    End If
                        
                    'CAB.SetFocus
                    Me.Requery
                    DoCmd.ShowAllRecords
                    DoCmd.GoToControl ("CAB")
                    DoCmd.FindRecord strNewCAB
                    strSearch = CAB.Text
                               
                        If strSearch = strNewCAB Then
                            'CAB.SetFocus
                            Me.Requery
                            DoCmd.ShowAllRecords
                            DoCmd.GoToControl ("CAB")
                            DoCmd.FindRecord strOldCAB
                            MsgBox "" & strSearch & " Is Taken - Please Try Again.", _
                                    , "Important Information"
                            Me.Refresh
                            Exit Sub
                        Else
                            DoCmd.GoToControl ("CAB")
                            DoCmd.FindRecord strOldCAB
                            txtoldcab.Visible = True
                            txtoldcab.SetFocus
                            txtoldcab.Locked = False
                            txtoldcab.Value = strOldCAB
                            txtoldcab.Locked = True
                            CAB.SetFocus
                            txtoldcab.Visible = False
                            CAB.Value = strNewCAB
                            CAB.Locked = True
                            EditCAB = False
                            DoCmd.FindRecord strNewCAB
                            DoCmd.RunCommand acCmdSaveRecord
                            MsgBox "Cab #" & strOldCAB & " Has Been Changed To Cab #" & strNewCAB & "", _
                                    , "Important Information"
                            Me.Refresh
                        End If
            End If
            
        End If
    End Sub

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

Similar Threads

  1. Replies: 7
    Last Post: 12-10-2018, 05:24 PM
  2. Replies: 5
    Last Post: 03-30-2010, 12:53 PM
  3. DoCmd.OpenForm Modification
    By alsoto in forum Forms
    Replies: 6
    Last Post: 05-01-2009, 07:28 AM
  4. Replies: 0
    Last Post: 03-11-2009, 11:40 AM
  5. DoCmd.SendObject Help
    By bgreer5050 in forum Programming
    Replies: 0
    Last Post: 01-12-2007, 06:27 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