-
Mar 31st, 2007, 10:43 AM
#1
Thread Starter
Addicted Member
[RESOLVED]Deleting,next,previous record issues
VB6 is connected to MS Access using ADO. On the form, I have Project name (combo box) and projectID from table tbl_project. I also have on the form, Risk ID, Risk name, impact and probability from table tbl_risk.
There is a delete command button with this code:
Code:
Private Sub cmdDelete_Click()
If MsgBox("Are you sure you want to delete this record?", vbYesNo + vbQuestion, "Delete?") = vbNo Then 'check if you really want to delete this record
Exit Sub 'exit the command
Else
If Not (rs.BOF = True Or rs.EOF = True) Then
rs.Delete 'delete the current record
If Not (rs.BOF = True Or rs.EOF = True) Then
rs.MoveNext 'move next
If rs.EOF Then rs.MoveLast
fillfields
End If
End If
End If
End Sub
When I select this command button and select 'yes' to delete, the records does get deleted but I also get this error: Object variable or with block variable not set.
This error also occurs when I click on a command button to search for next record or previous record.
I think its something to do with the combo box for project name.
What shall I do? Thanks
Last edited by wai1985; Apr 1st, 2007 at 08:33 AM.
-
Mar 31st, 2007, 02:39 PM
#2
Re: Deleting,next,previous record issues
You missed a vital piece of information.. Where (on which line) does the error occur?
-
Mar 31st, 2007, 02:54 PM
#3
Thread Starter
Addicted Member
Re: Deleting,next,previous record issues
It highlights this code which has the error:
Code:
cboprojectname.Text = rs1.Fields("ProjectName")
Which is within this code:
Code:
Public Sub fillfields()
If Not (rs.BOF = True Or rs.EOF = True) Then 'Checks if we are at the first or last record. This is use a lot.
Text1.Text = rs.Fields("RiskID")
Text2.Text = rs.Fields("NameOfTheRisk") 'as above
impact.Text = rs.Fields("Impact(0-10)")
likelihood.Text = rs.Fields("Likelihood(0-10)")
furtherinfo.Text = rs.Fields("FurtherInformation")
cboprojectname.Text = rs1.Fields("ProjectName") 'as above
Else
MsgBox "Either you are at the first record or the last record.", vbExclamation, "Cannot Move"
End If
End Sub
-
Mar 31st, 2007, 02:59 PM
#4
Re: Deleting,next,previous record issues
Check the spelling of the control name.. cboprojectname is not correct.
-
Mar 31st, 2007, 03:06 PM
#5
Thread Starter
Addicted Member
Re: Deleting,next,previous record issues
I have checked the combo box name and it is correct. The thing is the projectID is linked with the table in risks. Could it be something to do with that?
-
Mar 31st, 2007, 03:10 PM
#6
Thread Starter
Addicted Member
Re: Deleting,next,previous record issues
I think I may know what the problem is. The combo box is within Private Sub Fillfields. When either buttons next, previous or delete records are clicked, the code within these picks up all the fields from Fillfields. However the combo box has a record from a DIFFERENT table so it doesnt recognise this record. That make sense?
How do I go around this?
-
Mar 31st, 2007, 03:19 PM
#7
Re: Deleting,next,previous record issues
That's odd.. if the field isn't in the recordset, you should be getting the error "Item cannot be found in the collection ..."
Is the ProjectName field in your recordset? (which is created with the rs.Open line)
-
Apr 1st, 2007, 08:32 AM
#8
Thread Starter
Addicted Member
Re: Deleting,next,previous record issues
Hey I got it working now. I basically took that line of code out and put it in form load and that did the trick! Thanks anyways
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|