locked
Combo box selection is changing table records RRS feed

  • Question

  • hi

    hi everyone!

    I'm pretty new to Access, I've been using it less than 3 months.

    I have a form named: frmSearchPetname that has a subform, named: subfSearchPetname. The main form has a combo box along with a button. The users select the name of a pet then click the "search" button.

    The main and subform recordsource is to: tblAnimalInfo

    The combo box is bounded to tblAnimalInfo.petName

    The search works great, but the issue i am having is that it is changing the records in my table.

    I can definitely send my db to you if you need to look at it.

    here is the code i've written for the form:

    Option Explicit
    Option Compare Database
    
    Private Sub btnSearch_Click()
    
        Dim SQLstr As String
        
            SQLstr = "SELECT tblAnimalInfo.[petname], tblAnimalInfo.[monthofentry], " _
                        & " tblAnimalInfo.[numofwalks], tblAnimalInfo.[numofsleep], tblAnimalInfo.[numofdailymeals] " _
                            & " FROM tblAnimalInfo " _
                                & " WHERE tblAnimalInfo.[petname] = """ & Me.cmbxPetName & """"
                                
            Me.subfSearchPetName.Form.RecordSource = SQLstr
                            
    End Sub
    

    I'm not too sure what i'm doing wrong. Could it be that i'm not locking something that i should be?

    Thanks for dropping by and taking a look!

    Thursday, February 9, 2017 5:11 AM

Answers

  • Hi,

    Try removing the Control Source of your Combobox to make it unbound. In other words, remove petName. If you do want to add a petName or change it, add a Textbox on the form for it.

    Hope it helps...

    • Marked as answer by t_890 Thursday, February 9, 2017 5:32 AM
    Thursday, February 9, 2017 5:18 AM

All replies

  • Hi,

    Try removing the Control Source of your Combobox to make it unbound. In other words, remove petName. If you do want to add a petName or change it, add a Textbox on the form for it.

    Hope it helps...

    • Marked as answer by t_890 Thursday, February 9, 2017 5:32 AM
    Thursday, February 9, 2017 5:18 AM
  • it worked! omg that was such a dummy move i made. Thanks so much dbGuy :)
    Thursday, February 9, 2017 5:33 AM
  • Hi, You're welcome. Glad to hear you got it sorted out. Good luck with your project.
    Thursday, February 9, 2017 2:36 PM
  • yea thanks! my main project is @ work, so @ home i made myself a practice database with a similar lay out. it has helped me work things out (most things).
    Friday, February 10, 2017 7:31 AM