Visual Basic 6 Problem - Connecting to Access

Discussion in 'Software' started by kclazaroux, Dec 3, 2006.

  1. kclazaroux

    kclazaroux Private E-2

    For my assignment I have been given an Access database, and I need to create a program in VB that enables you to view, edit, delete etc details from the access database. I have to do this for several forms, at the moment I have been concentrating on one to get it working as the rest will pretty much be duplicates but I have run into a problem...

    I have uploaded the VB forms and project to the net, here is the link, make sure you change the "source=..." piece of code to where the access file is situated on YOUR computer and you should be ready to go.

    If anyone can see what I've done wrong or am missing, fix it or offer suggestions it will be greatly appreciated

    http://www.yourfilehost.com/media.php?cat=other&file=Prog1.zip

    Basically as you'll be able to see, in the data grid you should be able to view the employee details, and be able to edit/delete/add data as appropriate. Also, when a certain button is selected, other ones will be greyed out where appropriate. As far as I can see the coding for all this is correct but obviously I have gone wrong somewhere!
     
  2. hannahDaley

    hannahDaley Private E-2



    I tried to look at it, but there is no program to open after the download. I can see the vbp file but there is no exe. What is the issue that you are having anyways?? Is it not connected to the db, or does it not store the new info correctly??
     
  3. kclazaroux

    kclazaroux Private E-2

    that is sorted now. I have a new problem however, lol, as it always goes!

    The forms are set up, and coded as well as I can see, the data grids work and they display the access tables that I have set up.

    There are txt boxes set up below the datagrid, with a textbox+label for each field that appears in the table. So for example, say the fields in the table in the datagrid are 'ID, Name, Age, Reference', then there are txt boxes below that copy those. What should happen is when I click on one of the rows of data in the datagrid, the txtboxes will fill with the relative data of that row. It doesn't however. Here is the code for one of the forms:

    I currently have the code that I *think* should place the data into the txtboxes as a green note as when I put them in as proper code, I get a variable error. Anyways, here is the code:



    Option Explicit
    Dim rsfrmEmployee As ADODB.Recordset


    Private Sub cmdBTMenu_Click()
    Form2.Show
    Form1.Hide
    End Sub

    Private Sub cmdCancel_Click()
    CancelDetails
    End Sub

    Private Sub CancelDetails()
    EnableDetails False
    cmdNew.Enabled = True
    cmdEdit.Enabled = True
    cmdUpdate.Enabled = False
    cmdDelete.Enabled = True
    cmdCancel.Enabled = False

    Set rsfrmEmployee = Nothing
    ReadFromData

    End Sub

    Private Sub cmdClose_Click()
    Unload Me
    End Sub

    Private Sub cmdDelete_Click()
    DeleteDetails
    End Sub

    Private Sub cmdEdit_Click()
    EditDetails
    End Sub

    Private Function DeleteDetails()

    Set rsfrmEmployee = New ADODB.Recordset

    rsfrmEmployee.Source = "Select * From frmEmployee Where Employee_Id = " & _
    datfrmEmployee.Recordset!Employee_ID

    Set rsfrmEmployee.ActiveConnection = conn

    conn.BeginTrans
    rsfrmEmployee.LockType = adLockOptimistic
    rsfrmEmployee.CursorType = adOpenDynamic
    rsfrmEmployee.Open
    rsfrmEmployee.Delete
    conn.CommitTrans
    datfrmEmployee.Refresh
    rsfrmEmployee.Close
    Set rsfrmEmployee = Nothing

    End Function

    Private Function EditDetails()

    ChangeDetails False

    EnableDetails True

    cmdNew.Enabled = False
    cmdEdit.Enabled = False
    cmdUpdate.Enabled = True
    cmdDelete.Enabled = False
    cmdCancel.Enabled = True

    End Function

    Private Sub cmdNew_Click()
    ChangeDetails True
    ResetDetails
    End Sub

    Private Function ResetDetails()
    Cmbstatus.ListIndex = 0

    End Function

    Private Function ChangeDetails(bNew As Boolean)

    EnableDetails True
    Set rsfrmEmployee = New ADODB.Recordset

    If bNew Then
    rsfrmEmployee.Source = "Select * From frmEmployee"
    Else
    rsfrmEmployee.Source = "Select * From frmEmployee Where Employee_Id = " _
    & datfrmEmployee.Recordset!Employee_ID
    End If


    Set rsfrmEmployee.ActiveConnection = conn
    rsfrmEmployee.LockType = adLockOptimistic
    rsfrmEmployeeCursorType = adOpenDynamic
    rsfrmEmployee.Open

    If bNew Then rsfrmEmployee.AddNew

    cmdNew.Enabled = False
    cmdEdit.Enabled = False
    cmdUpdate.Enabled = True
    cmdDelete.Enabled = False
    cmdCancel.Enabled = True

    End Function

    Private Sub cmdUpdate_Click()
    UpdateDetails
    End Sub

    Private Function UpdateDetails()

    conn.BeginTrans
    rsfrmEmployee![role_id] = ComboDataItem(CmbRole)
    rsfrmEmployee![Surname] = TextBox(txtSurname)

    rsfrmEmployee.Update
    conn.CommitTrans

    rsfrmEmployee.Close
    Set rsfrmEmployee = Nothing

    EnableDetails False
    cmdNew.Enabled = True
    cmdEdit.Enabled = True
    cmdUpdate.Enabled = False
    cmdDelete.Enabled = True
    cmdCancel.Enabled = False

    datfrmEmployee.Refresh
    Set rsfrmEmployee = Nothing

    End Function

    Private Sub dbgfrmEmployee_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
    ReadFromData
    End Sub


    Private Sub Form_Load()

    Set conn = New ADODB.Connection

    sConnect = "Provider = Microsoft.Jet.OLEDB.4.0;Data " _
    & "Source=C:\Documents and Settings\Kyle C\Desktop\Yr 2 *** 1 Prog\Cardb.mdb"
    conn.Open sConnect
    Set datfrmEmployee = New ADODB.Recordset
    Connection.ConnectionString = sConnect
    Connection.RecordSource = "select * from qryEmployee1"
    Connection.CommandType = adCmdText
    Connection.Refresh




    ReadFromData

    EnableDetails False
    cmdNew.Enabled = True
    cmdEdit.Enabled = True
    cmdUpdate.Enabled = False
    cmdDelete.Enabled = True
    cmdCancel.Enabled = False

    End Sub

    Sub ReadFromData()

    ' With datfrmEmployee.Recordset
    ' txtID.Text = ![Employee_ID]
    ' txtSurname.Text = ![Surname]
    ' txtForename.Text = ![Forename]
    ' CmbRole.Text = ![Employee_Status]
    ' txtAddress1.Text = ![Address1]
    ' txtAddress2.Text = ![Address2]
    ' txtAddress3.Text = ![Address3]
    ' txtPostcode.Text = ![Postcode]
    ' txtTele.Text = ![TelNo]
    ' End With

    End Sub

    Private Function EnableDetails(bEnable As Boolean)
    CmbRole.Enabled = bEnable
    End Function

    Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single)

    End Sub
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds