-
May 31st, 2012, 04:07 PM
#1
Thread Starter
New Member
Run time Error 3265
I wrote a code for saving data in an ms access database and i get the following error message "run time error 3265" item cannot be found in the collection corresponding to the requested name or ordinal
below is the code giving me error message
Private Sub CmdSave_Click()
'On Error Resume Next
AdodSam.Recordset.Fields("District") = DataCmbHF.Text
AdodSam.Recordset.Fields("SubDist") = TxtSubdist.Text
AdodSam.Recordset.Fields("HealthF") = txtdist.Text
AdodSam.Recordset.Fields("Period") = DTPicker1.Value
AdodSam.Recordset.Fields("RUTFRcv") = txtRcvd.Text
AdodSam.Recordset.Fields("RUTFRcvkg") = txtRcvkg.Text
AdodSam.Recordset.Fields("RUTFissue") = TxtIssue.Text
AdodSam.Recordset.Fields("RUTFissuekg") = txtIssuekg.Text
AdodSam.Recordset.Fields("RUTFbal") = txtBal.Text
AdodSam.Recordset.Fields("RUTFbalkg") = txtbalkg.Text
AdodSam.Recordset.Fields("A") = txtA.Text
AdodSam.Recordset.Fields("B1") = TxtB1.Text
AdodSam.Recordset.Fields("B2") = TxtB2.Text
AdodSam.Recordset.Fields("B3") = TxtB3.Text
AdodSam.Recordset.Fields("C") = TxtC.Text
AdodSam.Recordset.Fields("D") = TxtD.Text
AdodSam.Recordset.Fields("E1") = TxtE1.Text
AdodSam.Recordset.Fields("E2") = TxtE2.Text
AdodSam.Recordset.Fields("E3") = TxtE3.Text
AdodSam.Recordset.Fields("E4") = TxtE4.Text
AdodSam.Recordset.Fields("F") = TxtF.Text
AdodSam.Recordset.Fields("G") = TxtG.Text
AdodSam.Recordset.Fields("H") = TxtH.Text
AdodSam.Recordset.Fields("E1per") = Text1.Text
AdodSam.Recordset.Fields("E2per") = Text2.Text
AdodSam.Recordset.Fields("E3per") = Text3.Text
AdodSam.Recordset.Fields("E4per") = Text4.Text
AdodSam.Recordset.Fields("E5per") = Text5.Text
AdodSam.Recordset.UpdateBatch
AdodSam.Refresh
MsgBox "Data Saved safely"
End Sub
-
May 31st, 2012, 04:13 PM
#2
Re: Run time Error 3265
I don't see how you can expect us to know which item cannot be found.. Maybe a misspelling, who knows? Maybe it one of the Recordset.Fields("?????")
You need to pinpoint which line throws the error and then we can take it from there
Last edited by jmsrickland; May 31st, 2012 at 04:17 PM.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
May 31st, 2012, 04:13 PM
#3
Re: Run time Error 3265
Don't use On Error Resume Next - comment it out and run your code again.
Execution will stop exactly where the error occurs - that field could be misspelled or perhaps it doesn't exist.
-
May 31st, 2012, 04:19 PM
#4
Re: Run time Error 3265
Originally Posted by RhinoBull
Don't use On Error Resume Next - comment it out and run your code again.
Execution will stop exactly where the error occurs - that field could be misspelled or perhaps it doesn't exist.
His On Error Resume Next is commented out
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
May 31st, 2012, 04:32 PM
#5
Re: Run time Error 3265
So which line is throwing the error?
Your issue is likely to be either
1: The fieldname is not spelled the same as in the database
2: The field does not exist in the database
3: The field was not included in the select statement that generated the recordset
4: The field was assigned an alias in the select statement that is different than the name you are using when you get the error.
-
Jun 1st, 2012, 02:51 AM
#6
Thread Starter
New Member
Re: Run time Error 3265
Thanks for the prompt response
I copied the field names directly from the database and yet i face this error.
The error start's from line one (AdodSam.Recordset.Fields("District") = DataCmbHF.Text).
if i comment it out it jump's to line four (AdodSam.Recordset.Fields("Period") = DTPicker1.Value)
so any line of code that is commented out the error jumps to the next line of code.
But i've cross checked to be sure of misspelling.
Thanks and waiting for response
-
Jun 1st, 2012, 03:14 AM
#7
Re: Run time Error 3265
You might find something useful in the Database Development FAQ.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Jun 1st, 2012, 04:12 AM
#8
Thread Starter
New Member
Re: Run time Error 3265
thanks to you all
I've implemented all suggestions but my problem (run time error 3265) still persist
-
Jun 1st, 2012, 04:34 AM
#9
Re: Run time Error 3265
This is how I wrote the save method for a program I created a while ago:
vb Code:
'save the current record created On Error GoTo HandleSaveErrors 'if an error occurs, let "HandleSaveErrors" If frmNewcontact.txtLast.Text = "" Or frmNewcontact.txtFirst.Text = "" Or frmNewcontact.txtSNum.Text = "" _ Or frmNewcontact.txtSName.Text = "" Or frmNewcontact.txtCity.Text = "" Or frmNewcontact.txtPostCode.Text = "" _ Or frmNewcontact.txtContactID.Text = "" Or frmNewcontact.txtPrefix.Text = "" Or frmNewcontact.txtPhone.Text = "" Then MsgBox "A Field was left empty. All Fields must contain valid data", vbOKOnly Exit Sub End If If Not frmNewcontact.txtContactID.Text = rs.Fields("CustomerID") Then rs.AddNew 'adding new record Else rs.Find frmNewcontact.txtContactID.Text = rs.Fields("CustomerID") End If rs.Fields("CustomerID") = frmNewcontact.txtContactID.Text 'Saves the customer ID to the database rs.Fields("Prefix") = frmNewcontact.txtPrefix.Text 'The customer's prefix rs.Fields("FirstName") = frmNewcontact.txtFirst.Text 'The customer's first name rs.Fields("LastName") = frmNewcontact.txtLast.Text 'The customer's last name rs.Fields("FirstEmail") = frmNewcontact.txtFirstEmail.Text 'The customer's first email address rs.Fields("SecondEmail") = frmNewcontact.txtSecondEmail.Text 'The customer's second email address rs.Fields("StreetNumber") = frmNewcontact.txtSNum.Text 'The customer's street number rs.Fields("StreetName") = frmNewcontact.txtSName.Text 'The customer's street name rs.Fields("City") = frmNewcontact.txtCity.Text 'The customer's city rs.Fields("PostCode") = frmNewcontact.txtPostCode.Text 'The customer's PostCode rs.Fields("Phone") = frmNewcontact.txtPhone.Text 'The customer's phone number rs.Fields("Mobile") = frmNewcontact.txtMobile.Text 'The customer's mobile number rs.Fields("InstantMessenger") = frmNewcontact.txtIM.Text 'The email address the customer uses for instant messaging rs.Fields("IM Details") = frmNewcontact.txtIMDetails.Text 'Other details associated with the customers instant messaging rs.Update 'Handle the data HandleSaveErrors: Select Case Err.Number Case 3022 'duplicate primary key strMessage = "Duplicate Customer Field" MsgBox strMessage, vbExclamation, "Database Error" rs.cancelUpdate Case 3058 'Primary key left blank strMessage = "Field was left empty" MsgBox strMessage, vbExclamation, "Database Error" rs.cancelUpdate Case Else strMessage = "Record could not be saved. " & vbCrLf _ & Err.Description Resume Next End Select
Edit:
Can you verify that the program is actually connecting to the database in the first place?
Last edited by Nightwalker83; Jun 1st, 2012 at 04:36 AM.
Reason: Adding more!
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Jun 1st, 2012, 04:46 AM
#10
Re: Run time Error 3265
What code are you using to retrieve the records ?
Can you use * instead (populate the rs with all fields)
-
Jun 1st, 2012, 04:56 AM
#11
Re: Run time Error 3265
vb Code:
Update = False 'turn MousePointer to HourGlass to show that we are busy processing Me.MousePointer = vbHourglass 'instantiate the connection object Set cn = New ADODB.Connection 'specify the connectionstring cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & App.Path & "\Customers.mdb" 'open the connection cn.Open 'instantiate the recordset object Set rs = New ADODB.Recordset 'open the recordset With rs .Open "tableCustomers", cn, adOpenKeyset, adLockPessimistic, adCmdTable 'loop through the records until reaching the end or last record frmNewcontact.txtContactID.Text = rs.Fields("CustomerID") 'Retrieves the customer ID to the database frmNewcontact.txtPrefix.Text = rs.Fields("Prefix") 'The customer's prefix frmNewcontact.txtFirst.Text = rs.Fields("FirstName") 'The customer's first name frmNewcontact.txtLast.Text = rs.Fields("LastName") 'The customer's last name frmNewcontact.txtFirstEmail.Text = rs.Fields("FirstEmail") 'The customer's first email address 'frmNewcontact.txtSecondEmail.Text = rs.Fields("SecondEmail") 'The customer's second email address frmNewcontact.txtSNum.Text = rs.Fields("StreetNumber") 'The customer's street number frmNewcontact.txtSName.Text = rs.Fields("StreetName") 'The customer's street name frmNewcontact.txtCity.Text = rs.Fields("City") 'The customer's city frmNewcontact.txtPostCode.Text = rs.Fields("PostCode") 'The customer's PostCode frmNewcontact.txtPhone.Text = rs.Fields("Phone") 'The customer's phone number frmNewcontact.txtMobile.Text = rs.Fields("Mobile") 'The customer's mobile number ' frmNewcontact.txtIM.Text = rs.Fields("InstantMessenger") 'The email address the customer uses for instant messaging ' frmNewcontact.txtIMDetails.Text = rs.Fields("IM Details") 'Other details associated with the customers instant messaging Me.MousePointer = vbNormal 'sets the mouse pointer to the normal arrow End With
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Jun 1st, 2012, 04:49 PM
#12
Thread Starter
New Member
Re: Run time Error 3265
Please i still have my run time error 3265. In fact i can't proceed with my project. I'm really in need
-
Jun 1st, 2012, 05:08 PM
#13
Re: Run time Error 3265
Show us how you are populating the recordset.
-
Jun 1st, 2012, 05:27 PM
#14
Re: Run time Error 3265
Code:
AdodSam.Recordset.Fields("District") = DataCmbHF.Text <--- This cause error
AdodSam.Recordset.Fields("SubDist") = TxtSubdist.Text <---- This does not
AdodSam.Recordset.Fields("HealthF") = txtdist.Text <---- This does not
AdodSam.Recordset.Fields("Period") = DTPicker1.Value <---- This causes error
From above it appears that those with = txtSomething.Text works but the two that say DataCmbHF.Text and DTPicker1.Value do not. So, I have this question....Do all the ones that have txtSomething.Text work? Maybe it's just those two and what is DataCmbHF and DTPicker1? Could it have anything to do with those two controls?
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Jun 1st, 2012, 05:34 PM
#15
Thread Starter
New Member
Re: Run time Error 3265
this is what i have
Private Sub form_load()
With AdodSam
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\NUT_SAM.mdb;Persist Security Info=False"
.RecordSource = "select * from SAM"
.Refresh
End With
End Sub
Private Sub CmdSave_Click()
AdodSam.Recordset.Fields("District") = DataCmbHF.Text
AdodSam.Recordset.Fields("SubDist") = TxtSubdist.Text
AdodSam.Recordset.Fields("HealthF") = txtdist.Text
AdodSam.Recordset.Fields("Period") = DTPicker1.Value
AdodSam.Recordset.Fields("RUTFRcv") = txtRcvd.Text
AdodSam.Recordset.Fields("RUTFRcvkg") = txtRcvkg.Text
AdodSam.Recordset.Fields("RUTFissue") = TxtIssue.Text
AdodSam.Recordset.Fields("RUTFissuekg") = txtIssuekg.Text
AdodSam.Recordset.Fields("RUTFbal") = txtBal.Text
AdodSam.Recordset.Fields("RUTFbalkg") = txtbalkg.Text
AdodSam.Recordset.Fields("A") = txtA.Text
AdodSam.Recordset.Fields("B1") = TxtB1.Text
AdodSam.Recordset.Fields("B2") = TxtB2.Text
AdodSam.Recordset.Fields("B3") = TxtB3.Text
AdodSam.Recordset.Fields("C") = TxtC.Text
AdodSam.Recordset.Fields("D") = TxtD.Text
AdodSam.Recordset.Fields("E1") = TxtE1.Text
AdodSam.Recordset.Fields("E2") = TxtE2.Text
AdodSam.Recordset.Fields("E3") = TxtE3.Text
AdodSam.Recordset.Fields("E4") = TxtE4.Text
AdodSam.Recordset.Fields("F") = TxtF.Text
AdodSam.Recordset.Fields("G") = TxtG.Text
AdodSam.Recordset.Fields("H") = TxtH.Text
AdodSam.Recordset.Fields("E1per") = Text1.Text
AdodSam.Recordset.Fields("E2per") = Text2.Text
AdodSam.Recordset.Fields("E3per") = Text3.Text
AdodSam.Recordset.Fields("E4per") = Text4.Text
AdodSam.Recordset.Fields("E5per") = Text5.Text
AdodSam.Recordset.UpdateBatch
AdodSam.Refresh
MsgBox "Data Saved safely"
End Sub
-
Jun 1st, 2012, 05:45 PM
#16
Re: Run time Error 3265
Dis you even read my post #14
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Jun 1st, 2012, 05:55 PM
#17
Thread Starter
New Member
Re: Run time Error 3265
you are right jmsrickland on above outline of which code contain an error and which does not but after (AdodSam.Recordset.Fields("Period") = DTPicker1.Value) the error continues till (AdodSam.Recordset.Fields("E5per") = Text5.Text)
-
Jun 1st, 2012, 05:56 PM
#18
Re: Run time Error 3265
The message indicates a missing or missspelled field reference. I would expect a different error if it were related to the values such as Type Mismatch or Invalid Use of Null
-
Jun 1st, 2012, 06:02 PM
#19
Re: Run time Error 3265
Originally Posted by youngman
you are right jmsrickland on above outline of which code contain an error and which does not but after (AdodSam.Recordset.Fields("Period") = DTPicker1.Value) the error continues till (AdodSam.Recordset.Fields("E5per") = Text5.Text)
In other words the error is on all lines to end beginning with AdodSam.Recordset.Fields("Period") = DTPicker1.Value. That's like saying that only two lines
AdodSam.Recordset.Fields("SubDist") = TxtSubdist.Text <---- This does not
AdodSam.Recordset.Fields("HealthF") = txtdist.Text <---- This does not
do not cause error and all the rest do. Is this correct?
Originally Posted by youngman
But i've cross checked to be sure of misspelling.
If you are absolutly positive then it sure isn't anything misspelled. So, we can eliminate everything in ("......"), you agree?
Last edited by jmsrickland; Jun 1st, 2012 at 06:09 PM.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Jun 1st, 2012, 06:08 PM
#20
Thread Starter
New Member
-
Jun 1st, 2012, 06:08 PM
#21
Re: Run time Error 3265
@ youngman,
Going on what jmsrickland said TxtSubdist.Text and DTPicker1.Value might need to be converted to the correct data type. Check which data type those field have in the database.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Jun 1st, 2012, 06:11 PM
#22
Re: Run time Error 3265
Originally Posted by Nightwalker83
@ youngman,
Going on what jmsrickland said TxtSubdist.Text and DTPicker1.Value might need to be converted to the correct data type. Check which data type those field have in the database.
He says all lines except the 2nd two cause errors. Post 20 affirms my question in post 19
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Jun 1st, 2012, 06:26 PM
#23
Re: Run time Error 3265
Is it possible that there is another select statement somewhere that is selecting only some of the fields and that is the one that is active at the time the error occurs.
Try setting a break point on the very first line in the cmd save sub. When it hits the breakpoint try placing your cursor over the portion of the left of the = sign and see if it tells you that it can not be found if not then place the cursor over the portion on the right of the = sign and see what it says.
Incorrect or invalid data assignments should not generate the error mentioned in the OP. They will generate a Type Mismatch or overflow error but should not generate Item not found in the collection that error indicates that you are referencing something that is not in the collection either by name or by index.
-
Jun 1st, 2012, 06:36 PM
#24
Re: Run time Error 3265
I just remembered a post from a while back where the poster was encountering a strange issue. I have never experienced such a problem but basically what was happening was when he used "Select * from Table" then referenced the fields by name as in the OP he was getting the same error message on most of the fields.
If he changed the select statement to select all the fields by name then there was no error.
You may want to try this an see what happens
-
Jun 1st, 2012, 08:58 PM
#25
Re: Run time Error 3265
@ DataMiser,
I think I came across the same post. This was the post I found.
Originally Posted by jmsrickland
He says all lines except the 2nd two cause errors. Post 20 affirms my question in post 19
Yes, and I'm asking him to double check the data type of those fields in the database to make sure they have been set correctly for the data they are receiving.
Last edited by Nightwalker83; Jun 1st, 2012 at 09:23 PM.
Reason: Fixed spelling!
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Jun 2nd, 2012, 07:13 AM
#26
Re: Run time Error 3265
On the line where you break with an error, repeat the line and comment out the original line.
And in the 2nd line, replace the right side of the equation with some simple value that you know is of the correct data type.
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
|