PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Run time Error 3265-VBForums
Results 1 to 26 of 26

Thread: Run time Error 3265

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    10

    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

  2. #2
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,072

    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.

  3. #3

  4. #4
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,072

    Re: Run time Error 3265

    Quote Originally Posted by RhinoBull View Post
    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.

  5. #5
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,573

    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.

  6. #6

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    10

    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

  7. #7
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,346

    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.
    Please consider giving me some rep points if I help you a lot.
    Please rate my post if you find it helpful!
    Technology is a dangerous thing in the hands of an idiot! I am that idiot.

  8. #8

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    10

    Re: Run time Error 3265

    thanks to you all
    I've implemented all suggestions but my problem (run time error 3265) still persist

  9. #9
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,346

    Re: Run time Error 3265

    This is how I wrote the save method for a program I created a while ago:

    vb Code:
    1. 'save the current record created
    2.      On Error GoTo HandleSaveErrors 'if an error occurs, let "HandleSaveErrors"
    3.       If frmNewcontact.txtLast.Text = "" Or frmNewcontact.txtFirst.Text = "" Or frmNewcontact.txtSNum.Text = "" _
    4.         Or frmNewcontact.txtSName.Text = "" Or frmNewcontact.txtCity.Text = "" Or frmNewcontact.txtPostCode.Text = "" _
    5.      Or frmNewcontact.txtContactID.Text = "" Or frmNewcontact.txtPrefix.Text = "" Or frmNewcontact.txtPhone.Text = "" Then
    6.             MsgBox "A Field was left empty. All Fields must contain valid data", vbOKOnly
    7.             Exit Sub
    8.             End If
    9.             If Not frmNewcontact.txtContactID.Text = rs.Fields("CustomerID") Then
    10.             rs.AddNew 'adding new record
    11.              Else
    12.              rs.Find frmNewcontact.txtContactID.Text = rs.Fields("CustomerID")
    13.              End If
    14.                    rs.Fields("CustomerID") = frmNewcontact.txtContactID.Text 'Saves the customer ID to the database
    15.              rs.Fields("Prefix") = frmNewcontact.txtPrefix.Text   'The customer's prefix
    16.              rs.Fields("FirstName") = frmNewcontact.txtFirst.Text  'The customer's first name
    17.             rs.Fields("LastName") = frmNewcontact.txtLast.Text  'The customer's last name
    18.             rs.Fields("FirstEmail") = frmNewcontact.txtFirstEmail.Text  'The customer's first email address
    19.             rs.Fields("SecondEmail") = frmNewcontact.txtSecondEmail.Text  'The customer's second email address
    20.             rs.Fields("StreetNumber") = frmNewcontact.txtSNum.Text  'The customer's street number
    21.             rs.Fields("StreetName") = frmNewcontact.txtSName.Text  'The customer's street name
    22.             rs.Fields("City") = frmNewcontact.txtCity.Text  'The customer's city
    23.             rs.Fields("PostCode") = frmNewcontact.txtPostCode.Text  'The customer's PostCode
    24.             rs.Fields("Phone") = frmNewcontact.txtPhone.Text  'The customer's phone number
    25.             rs.Fields("Mobile") = frmNewcontact.txtMobile.Text  'The customer's mobile number
    26.             rs.Fields("InstantMessenger") = frmNewcontact.txtIM.Text  'The email address the customer uses for instant messaging
    27.             rs.Fields("IM Details") = frmNewcontact.txtIMDetails.Text  'Other details associated with the customers instant messaging
    28.             rs.Update 'Handle the data
    29.            
    30.        
    31.  
    32. HandleSaveErrors:
    33.    
    34.     Select Case Err.Number
    35.          Case 3022 'duplicate primary key
    36.          strMessage = "Duplicate Customer Field"
    37.          MsgBox strMessage, vbExclamation, "Database Error"
    38.          rs.cancelUpdate
    39.        
    40.         Case 3058       'Primary key left blank
    41.             strMessage = "Field was left empty"
    42.             MsgBox strMessage, vbExclamation, "Database Error"
    43.             rs.cancelUpdate
    44.         Case Else
    45.             strMessage = "Record could not be saved. " & vbCrLf _
    46.                             & Err.Description
    47.             Resume Next
    48.     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.
    Please consider giving me some rep points if I help you a lot.
    Please rate my post if you find it helpful!
    Technology is a dangerous thing in the hands of an idiot! I am that idiot.

  10. #10
    Frenzied Member
    Join Date
    Dec 2008
    Posts
    1,138

    Re: Run time Error 3265

    What code are you using to retrieve the records ?
    Can you use * instead (populate the rs with all fields)

  11. #11
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,346

    Re: Run time Error 3265

    vb Code:
    1. Update = False
    2.     'turn MousePointer to HourGlass to show that we are busy processing
    3.     Me.MousePointer = vbHourglass
    4.     'instantiate the connection object
    5.     Set cn = New ADODB.Connection
    6.     'specify the connectionstring
    7.     cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    8.                           "Data Source=" & App.Path & "\Customers.mdb"
    9.     'open the connection
    10.     cn.Open
    11.    
    12.     'instantiate the recordset object
    13.     Set rs = New ADODB.Recordset
    14.     'open the recordset
    15.     With rs
    16.         .Open "tableCustomers", cn, adOpenKeyset, adLockPessimistic, adCmdTable
    17.            
    18.         'loop through the records until reaching the end or last record
    19.         frmNewcontact.txtContactID.Text = rs.Fields("CustomerID")  'Retrieves the customer ID to the database
    20.     frmNewcontact.txtPrefix.Text = rs.Fields("Prefix") 'The customer's prefix
    21.     frmNewcontact.txtFirst.Text = rs.Fields("FirstName")  'The customer's first name
    22.     frmNewcontact.txtLast.Text = rs.Fields("LastName")  'The customer's last name
    23.     frmNewcontact.txtFirstEmail.Text = rs.Fields("FirstEmail")  'The customer's first email address
    24.     'frmNewcontact.txtSecondEmail.Text = rs.Fields("SecondEmail") 'The customer's second email address
    25.     frmNewcontact.txtSNum.Text = rs.Fields("StreetNumber")  'The customer's street number
    26.      frmNewcontact.txtSName.Text = rs.Fields("StreetName")  'The customer's street name
    27.      frmNewcontact.txtCity.Text = rs.Fields("City") 'The customer's city
    28.      frmNewcontact.txtPostCode.Text = rs.Fields("PostCode")  'The customer's PostCode
    29.    frmNewcontact.txtPhone.Text = rs.Fields("Phone") 'The customer's phone number
    30.     frmNewcontact.txtMobile.Text = rs.Fields("Mobile")  'The customer's mobile number
    31. '    frmNewcontact.txtIM.Text = rs.Fields("InstantMessenger")   'The email address the customer uses for instant messaging
    32.  '   frmNewcontact.txtIMDetails.Text = rs.Fields("IM Details") 'Other details associated with the customers instant messaging
    33.     Me.MousePointer = vbNormal 'sets the mouse pointer to the normal arrow
    34.     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.
    Please consider giving me some rep points if I help you a lot.
    Please rate my post if you find it helpful!
    Technology is a dangerous thing in the hands of an idiot! I am that idiot.

  12. #12

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    10

    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

  13. #13
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,573

    Re: Run time Error 3265

    Show us how you are populating the recordset.

  14. #14
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,072

    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.

  15. #15

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    10

    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

  16. #16
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,072

    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.

  17. #17

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    10

    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)

  18. #18
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,573

    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

  19. #19
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,072

    Re: Run time Error 3265

    Quote Originally Posted by youngman View Post
    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?

    Quote Originally Posted by youngman View Post
    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.

  20. #20

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    10

    Re: Run time Error 3265

    Yes Jmsrickland

  21. #21
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,346

    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.
    Please consider giving me some rep points if I help you a lot.
    Please rate my post if you find it helpful!
    Technology is a dangerous thing in the hands of an idiot! I am that idiot.

  22. #22
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,072

    Re: Run time Error 3265

    Quote Originally Posted by Nightwalker83 View Post
    @ 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.

  23. #23
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,573

    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.

  24. #24
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,573

    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

  25. #25
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,346

    Re: Run time Error 3265

    @ DataMiser,

    I think I came across the same post. This was the post I found.

    Quote Originally Posted by jmsrickland View Post
    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.
    Please consider giving me some rep points if I help you a lot.
    Please rate my post if you find it helpful!
    Technology is a dangerous thing in the hands of an idiot! I am that idiot.

  26. #26
    Frenzied Member
    Join Date
    Dec 2008
    Posts
    1,138

    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
  •  



Featured


Click Here to Expand Forum to Full Width