Results 1 to 6 of 6
  1. #1
    sharVyn is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Feb 2012
    Posts
    6

    I can't find the bug. Please help

    i can't find the bug in this coding.
    can't someone help me?


    note: i have a table "tblCustDetails" and a form "FrmCustomerDetails"
    I can't move on without finding the bug, it might occur in my other forms

    Code:
    Option Compare Database
    Option Explicit
    
    'Declaring Variables to be used
    Dim dbsCustomer As DAO.Database
    Dim rstCustomer As DAO.Recordset
    Dim PresenceCheck As Boolean
    
    '--------------------------------------------------------
    'Purpose: to load Customer Details form with Customers's first record.
    'Event  : Form Load
    '--------------------------------------------------------
    Private Sub Form_Load()
    
        'Executing database & recordset
        Set dbsCustomer = CurrentDb
        Set rstCustomer = dbsCustomer.OpenRecordset("tblCustDetails", dbOpenDynaset)
        
        'To disable CustomerId textbox
        Me.txtcustomerid = True
        
        'set Search Client combox to nothing
        Me.cmbSearchCustomer = ""
        
        'Cycle to first record and display record
        rstCustomer.MoveFirst
        
        
        'Calling procedure to display Customer Record
        Call displayRecord
       
       
       
    End Sub
    
    
    '-----------------------------------------------
    'Purpose: Displaying record while updating search box
    'Event  : lookup value for combo box after update
    '-----------------------------------------------
    
    Private Sub cmbSearchCustomer_AfterUpdate()
    
         With cmbSearchCustomer
            'Pushing data to form from table
            Me.txtcustomerid = .Column(0)
            Me.txtsurname = .Column(1)
            Me.txtname = .Column(2)
            Me.txtaddress = .Column(3)
            Me.txtrentalid = .Column(4)
            Me.txtTelephone = .Column(5)
            Me.txtMobile = .Column(6)
            Me.txtoverdue = .Column(7)
            Me.txtfine = .Column(8)
        End With
        
    End Sub
    
    
    Private Sub cmbSearchCustomer_LostFocus()
       'Set Search Combo Box to nothing
        Me.cmbSearchCustomer = ""
    End Sub
    
    
    '---------------------------------
    'Purpose: Cycle to previous record
    'Event: On click previous button
    '---------------------------------
    
    Private Sub btnPrev_Click()
        'Cycle to previous record
        rstCustomer.MovePrevious
         
        'Display message if current record is at beginning of file
        If rstCustomer.BOF Then
            rstCustomer.MoveFirst         'Remain at the first record
            MsgBox "Cannot Cycle backwards. Already at the first record!", vbInformation + vbOKOnly, "Calliope Video store"
        End If
        
        Call displayRecord      'Display the data from Customer table
    
    End Sub
    
    '------------------------------
    'Purpose: Cycle to next record
    'Event: On click next record
    '------------------------------
    
    Private Sub btnNext_Click()
    
        'Cycle to next record
        rstCustomer.MoveNext
       
        'Display message if current record is at end of file
        If rstCustomer.EOF Then
            rstCustomer.MoveLast
            MsgBox "Cannot cycle forward. Already at the last record!", vbInformation + vbOKOnly, "Calliope Video Store"""
        End If
        
        Call displayRecord          'Display the data from Customer table
        
    End Sub
    
    
    '------------------------------
    'Purpose: Add new record
    'Event  : On click add new record
    '------------------------------
    
    Private Sub btnNewRecord_Click()
            'Set all fields to null
            Call clearForm
    
           'Enable the CustomerId text box
            Me.txtcustomerid.Enabled = True
    
            'set focus to CustomerId text box
            Me.txtcustomerid.SetFocus
    End Sub
    
    '-------------------------------------------
    'Purpose: Delete current record
    'Event  : On click delete button
    '-------------------------------------------
    Private Sub btnDeleteRecord_Click()
        'Using local Variable
        Dim DisplayMsg As String
        
        'Confirmation message
        DisplayMsg = MsgBox("Proceed with deletion of this record?", vbYesNo + vbQuestion, "Calliope Video Store")
          
           'If input is yes
            If DisplayMsg = vbYes Then
                
                
               'Delete current record
                With rstCustomer
                    .Delete 'delete current record
    
                    MsgBox "Current record deleted!", vbInformation + vbOKOnly, "Calliope Video Store"
                    .MoveNext   'Cycle to next record and display
    
                    If .EOF Then    'if at end of table
                        .MoveLast   'Stay to last record to avoid error
                        Call displayRecord  'display data into form
                    End If
               
                    Call displayRecord  'display data into form
                End With
            End If
    End Sub
    
    
    '-------------------------------------
    'Purpose: to save new record
    'Event Procedure: Save button on click
    '-------------------------------------
    Private Sub btnSaveRecord_Click()
        
        PresenceChck = False
        
        'Check if fields are empty by calling checkEmpty procedure
        Call checkEmpty
    
        'check if fields are empty
        If PresenceCheck = True Then
            'error message
             MsgBox "Record cannot be saved as it contains blank fields!", vbExclamation + vbOKOnly, "XYZ Co. Ltd"
             Exit Sub
             
        Else 'Save record
            rstClient.MoveLast  'Move to the last record
            rstClient.AddNew     'add a new record
            Call saveRecord      'Transfer the data from form to table
            
            rstClient.Update     'update the table
            MsgBox "The record has been saved successfully!", vbOKOnly + vbInformation, " XYZ Co. Ltd "
        End If
        End Sub
    
    
    '------------------------------------------
    'Purpose: to exit Client Form
    'Event: On click, open Main Menu
    '------------------------------------------
    Private Sub btnMainMenu_Click()
    
         'Close Customer Details Form
         dbsClient.Close
     
         'Close Customer Details record set
         rstCustomer.Close
     
         'Close Customer Form
         DoCmd.Close
        
        'Open Main Menu Form
        DoCmd.OpenForm "frmMainMenu"
    End Sub
    
    
    
    '---------------------------------------------------------------
    'Purpose: to display customer records from tblcustomer to Customer Form
    'Event: User Defined prcedure
    '----------------------------------------------------------------
    Private Sub displayRecord()
    
    'Display the data from table
        With rstCustomer
            Me.txtcustomerid = .Fields!CustID
            Me.txtsurname = .Fields!CustSurname
            Me.txtname = .Fields!CustName
            Me.txtrentalid = .Fields!RentalID
            Me.txtaddress = .Fields!Address
            Me.txttelephoneno = .Fields!TelephoneNo
            Me.txtmobileno = .Fields!MobileNo
            Me.txtoverdue = .Fields!Overdue
            Me.txtfine = .Fields!Fine
                    
        End With
     End Sub
    
    
    Private Sub clearForm()
    
           'Clears all the text boxes in the form
            Me.txtcustomerid = ""
            Me.txtsurname = ""
            Me.txtname = ""
            Me.txtrentalid = ""
            Me.txtaddress = ""
            Me.txttelephoneno = ""
            Me.txtmobileno = ""
            Me.txtoverdue = ""
            Me.txtfine = ""
            Me.cmbSearchCustomer = ""
        End Sub
    
    
    '----------------------------------------------------
    'Purpose: TO save all data from the form to the table
    'Event: User Defined procedure
    '----------------------------------------------------
    
    Private Sub saveRecord()
    
    'Save all data from the form into the table
        With rstCustomer
        .Fields!CustomerId = Me.txtcustomerid
        .Fields!Surname = Me.txtsurname
        .Fields!Name = Me.txtname
        .Fields!RentalID = Me.txtrentalid
        .Fields!Address = Me.txtaddress
        .Fields!TelephoneNo = Me.txttelephoneno
        .Fields!MobileNo = Me.txtmobileno
        .Fields!Overdue = Me.txtoverdue
        .Field!Fine = Me.txtfine
        End With
    End Sub
    
    
    '---------------------------------------------------
    'Purpose: Presence check done on empty fields
    'Event: User Defined procedure
    '---------------------------------------------------
    
    Private Sub checkEmpty()
        'Customer ID
        If Me.txtcustomerid = "" Then
            MsgBox "Please, enter a Customer Code!", vbOKOnly + vbExclamation, "Calliope Video Store"
            PresenceCheck = True
            Exit Sub
        End If
    
    
        'Surname
        If Me.txtsurname = "" Then
            MsgBox "Please enter Customer's Surname!", vbOKOnly + vbExclamation, "Calliope Video Store"
            PresenceCheck = True
            Exit Sub
        End If
        
        'Name
        If Me.txtname = "" Then
            MsgBox "Please enter Customer's Firstname", vbOKOnly + vbExclamation, "Calliope Video Store"
             PresenceCheck = True
            Exit Sub
        End If
        
        'Rental ID
        If Me.txtrentalid = "" Then
            MsgBox "Please enter Rental ID", vbOKOnly + vbExclamation, "Calliope Video Store"
            PresenceCheck = True
            Exit Sub
        End If
        
        'Address
        If Me.txtaddress = "" Then
            MsgBox "Please enter Customer's Address", vbOKOnly + vbExclamation, "XYZ Co. Ltd"
            PresenceCheck = True
            Exit Sub
        End If
    
    
        'Telephone Number
        If Me.txttelephoneno = "" Then
            MsgBox "Please enter Customer's Telephone Number", vbOKOnly + vbExclamation, "XYZ Co. Ltd"
            PresenceCheck = True
            Exit Sub
        End If
    
       
       'Mobile Number
        If Me.txtmobileno = "" Then
            MsgBox "Please enter Customer's Mobile Number", vbOKOnly + vbExclamation, "XYZ Co. Ltd"
            PresenceCheck = True
            Exit Sub
        End If
        
        
       'Overdue
        If Me.txtoverdue = "" Then
            MsgBox "Please state current status of customer's rental", vbOKOnly + vbExclamation, "XYZ Co. Ltd"
            PresenceCheck = True
            Exit Sub
        End If
        
        'Fine
        If txtoverdue <> "" Then
         If Me.txtfine = "" Then
             MsgBox "Please state the amount of fine the customer has to pay if ", vbOKOnly + vbExclamation, "XYZ Co. Ltd"
             PresenceCheck = True
             Exit Sub
        End If
        End If
        
        
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    What's the bug? What's the error? What happens or doesn't happen? It's tedious to look at 10 pages of code without knowing what we're looking for.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    If you go into your Code Module and go to 'Debug' and click on 'Compile Database' the Access Gnomes will point out any errors to you.

    Linq ;0)>

  4. #4
    SteveH2508 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2010
    Location
    Chelsea, London, England
    Posts
    117
    I'm not going to wade through all of that code but in the first few lines you have this:


    'To disable CustomerId textbox
    Me.txtcustomerid = True

    It should be
    Me.txtcustomerid.Enabled = False

  5. #5
    sharVyn is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Feb 2012
    Posts
    6
    I am really sorry for making you lose your time on this. The mistake came from wrongly labelled textboxes.
    Once again i am really very sorry.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    No big deal. Glad you got it sorted out.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. find and replace
    By rohini in forum Access
    Replies: 7
    Last Post: 05-17-2012, 05:23 AM
  2. Find file
    By forestgump in forum Programming
    Replies: 1
    Last Post: 05-15-2011, 10:44 AM
  3. Find a SUM
    By jcsports31 in forum Access
    Replies: 8
    Last Post: 09-14-2010, 10:07 AM
  4. Filter vs Find ?
    By Huddle in forum Access
    Replies: 4
    Last Post: 07-16-2010, 08:59 AM
  5. Find tables
    By Jaime in forum Access
    Replies: 2
    Last Post: 11-04-2009, 01:52 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