Access database with VB GUI


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Access database with VB GUI

Hybrid View

  1. #1
    Emma Guest

    Access database with VB GUI


    HELP!

    I am building a help desk for an assignment and am trying to add a new record
    to the database through VB. The AddNew statement works OK that I've assigned
    to a command button, but the MoveNext, Edit and Update statements that are
    assigned to another command button don't work. It comes up with runtime error
    #3246 'Action cancelled by associated object'.

    I'm going crazy trying to work out what I am doing wrong!

    Please help.

    xxx

    This is the code for my form so far (if its any help):

    Option Explicit
    Dim blnAdded As Boolean
    Dim varPreviousRecord As Variant
    Dim Location(0 To 10)
    Dim Priority(0 To 2)
    Dim FaultType(0 To 8)
    Dim Engineer(0 To 9)
    Dim ID(0 To 9)
    Dim Mobile(0 To 9)

    Private Sub Form_Load()
    Dim I As Integer

    Engineer(0) = "Spencer Buck"
    Engineer(1) = "Roger Duckworth"
    Engineer(2) = "Freddie Jackson"
    Engineer(3) = "Laura Lawler"
    Engineer(4) = "Agatha MacDermott"
    Engineer(5) = "Pedro Manito"
    Engineer(6) = "Shamus O'Toole"
    Engineer(7) = "Teddy Prendergast"
    Engineer(8) = "Nelly Smelly"
    Engineer(9) = "John Thomas"

    ID(0) = "BUC006"
    ID(1) = "DUC010"
    ID(2) = "JAC003"
    ID(3) = "LAW008"
    ID(4) = "MAC005"
    ID(5) = "MAN004"
    ID(6) = "OTO002"
    ID(7) = "PRE001"
    ID(8) = "SME009"
    ID(9) = "THO007"

    Mobile(0) = "07714888006"
    Mobile(1) = "07714888010"
    Mobile(2) = "07714888003"
    Mobile(3) = "07714888008"
    Mobile(4) = "07714888005"
    Mobile(5) = "07714888004"
    Mobile(6) = "07714888002"
    Mobile(7) = "07714888001"
    Mobile(8) = "07714888009"
    Mobile(9) = "07714888007"

    For I = 0 To 9
    cboEngineerName.AddItem Engineer(I)
    Next I

    Location(0) = "Accounts"
    Location(1) = "Administration"
    Location(2) = "Conference Room"
    Location(3) = "Human Resources"
    Location(4) = "Management 1"
    Location(5) = "Management 2"
    Location(6) = "Management 3"
    Location(7) = "Marketing"
    Location(8) = "Sales"
    Location(9) = "Warehouse"
    Location(10) = "Workshop"

    For I = 0 To 10
    cboFaultLocation.AddItem Location(I)
    Next I

    FaultType(0) = "Network Connection"
    FaultType(1) = "Fax"
    FaultType(2) = "PC - Hardware"
    FaultType(3) = "PC - Sofware"
    FaultType(4) = "Photocopier"
    FaultType(5) = "Printer"
    FaultType(6) = "Scanner"
    FaultType(7) = "Teleconferencing Equipment"
    FaultType(8) = "User Error"

    For I = 0 To 8
    cboFaultType.AddItem FaultType(I)
    Next I

    Priority(0) = "Low"
    Priority(1) = "Medium"
    Priority(2) = "High"

    For I = 0 To 2
    cboPriorityLevel.AddItem Priority(I)
    Next I

    End Sub

    Private Sub cboEngineerName_Click()

    txtEngineerID.Text = ID(cboEngineerName.ListIndex)
    txtMobileNo.Text = Mobile(cboEngineerName.ListIndex)

    End Sub

    Private Sub cmdMoveNext_Click()

    With datFaultLog.Recordset
    If .RecordCount > 0 Then
    If Not .EOF Then
    .MoveNext
    End If
    End If
    End With

    End Sub

    Private Sub cmdMovePrevious_Click()

    With datFaultLog.Recordset
    If .RecordCount > 0 Then
    If Not .BOF Then
    If blnAdded = False Then
    .MovePrevious
    End If
    End If
    End If
    End With

    End Sub

    Private Sub Form_Initialize()

    With datFaultLog.Recordset
    .MoveLast
    End With

    End Sub

    Private Sub cmdAddRecord_Click()

    cmdAddRecord.Visible = False
    cmdMovePrevious.Visible = False
    cmdMoveNext.Visible = False

    With datFaultLog.Recordset
    If .RecordCount > 0 Then
    varPreviousRecord = .Bookmark
    Else
    varPreviousRecord = ""
    End If
    .AddNew
    End With

    With txtFaultNo
    .Locked = False
    .Text = ""
    End With

    With txtDateTimeLogged
    .Locked = False
    .Text = Date & " " & Time
    .Locked = True
    End With

    With txtStatus
    .Locked = False
    .Text = "Open"
    .Locked = True
    End With

    With txtDateTimeCompleted
    .Locked = False
    .Text = ""
    .Locked = True
    End With

    With txtEmployeeName
    .Locked = False
    .Text = ""
    .SetFocus
    End With

    With txtContactNo
    .Locked = False
    .Text = ""
    End With

    With txtEngineerID
    .Locked = False
    .Text = ""
    .Locked = True
    End With

    With txtMobileNo
    .Locked = False
    .Text = ""
    .Locked = True
    End With

    With txtDescription
    .Locked = False
    .Text = ""
    End With

    With txtDiagnosis
    .Locked = False
    .Text = ""
    End With

    With txtWorkUndertaken
    .Locked = False
    .Text = ""
    End With

    With cboEngineerName
    .Locked = False
    .Text = ""
    End With

    With cboFaultLocation
    .Locked = False
    .Text = ""
    End With

    With cboFaultType
    .Locked = False
    .Text = ""
    End With

    With cboPriorityLevel
    .Locked = False
    .Text = ""
    End With

    End Sub

    Private Sub mnuHelpDeskMenu_Click()

    Load frmHelpDeskMenu
    frmHelpDeskMenu.Show
    Unload Me

    End Sub

    Private Sub cmdHelpDeskMenu_Click()

    Load frmHelpDeskMenu
    frmHelpDeskMenu.Show
    Unload Me

    End Sub

    Private Sub mnuExit_Click()

    End

    End Sub

    Private Sub cmdExit_Click()

    End

    End Sub

    Private Sub txtDescription_Change()

    If txtDescription.Locked = False Then
    cmdSaveRecord.Visible = True
    End If

    End Sub

    Private Sub cmdSaveRecord_Click()

    datFaultLog.Recordset.Update

    cmdSaveRecord.Visible = False
    cmdAddRecord.Visible = True
    cmdMovePrevious.Visible = True
    cmdMoveNext.Visible = True

    txtFaultNo.Locked = True
    txtEmployeeName.Locked = True
    txtContactNo.Locked = True
    txtDescription.Locked = True
    txtDiagnosis.Locked = True
    txtWorkUndertaken.Locked = True

    cboEngineerName.Locked = True
    cboFaultLocation.Locked = True
    cboFaultType.Locked = True
    cboPriorityLevel.Locked = True

    blnAdded = True

    End Sub



  2. #2
    Dave Harper Guest

    Re: Access database with VB GUI


    Hi Emma, I posted a response to your earlier request for advice which you
    may wish to review. However, your problems illustrate just why I prefer to
    work with unbound controls. Unfortunately I can't help you with the problem
    you have described at the moment. I would however suggest that you build
    in some error recovery routines to save getting fatal errors.
    Good luck
    Dave

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center