mlinville 0 Newbie Poster

Hi thanks for the help I am new to this so sorry if I’m slow. I am trying to make an Access Database I have a quarry that pulls data into a combo box and then auto fills the below text boxes. I want the user will then fill out the new data associated with the quarry data pulled. And then hit an Add bottom to add it to a new table called report. I keep getting an object error can you please advise. Thanks
Matt below is the code

Private Sub cboAdd_Click()
Dim cnn1 As ADODB.Connection
Dim rstcontact As ADODB.Recordset
Dim strCnn As String

'Check that all fields are filled in
cboLease.SetFocus
If cboLease.Text = "" Then
err = err + 1
MsgBox "Please fill in the name box!" & err
End If

'if no errors insert data
If err < 1 Then
' Open a connection.
    Set cnn1 = New ADODB.Connection
   mydb = "watertrucktest.accdb"
strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mydb


' Open report table.
    Set rstrepot = New ADODB.Recordset
    rstrepot.CursorType = adOpenKeyset
    rstrepot.LockType = adLockOptimistic
    rstrepot.Open "report", cnn1, , , adCmdTable


'get the new record data
rstrepot.AddNew
        rstrepot!LeaseName = cboLease
        rstrepot!Area = txtarea
        rstrepot!Run = txtrun
        rstrepot!Type = txttype
        rstrepot!Truck = cboTruck
        rstrepot!Driver = cboDriver
        rstrepot!Water = txtWater
        rstrepot!Requested = txtRequested
        rstrepot!Received = txtReceived
        rstrepot!Pulled = txtPulled
        rstrepot!Hi = txtHi
        rstrepot!Job = txtJob
        rstcontact.Update

' Show the newly added data.
        MsgBox "Well add: " & rstcontact!Name & " has been successfully added"


'close connections
rstcontact.Close
    cnn1.Close


Else
MsgBox "An Error has occurred, please check and try again"
End If

End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.