Help with Code to change RecordSource property

  • Thread starter HLCruz via AccessMonster.com
  • Start date
H

HLCruz via AccessMonster.com

I am trying to change the record source property of my form via code in VBA,
the code runs in the onclick event of a button.

I'd like for the code to create a criteria based on the selection of a combo
box. The value will be the record's street address.

The code I'm trying to piece together isn't working - the error I get is that
there is no such record. But, I happen to know that the record exists so I
suspect it's my code that is faulty.

Any help would be greatly appreciated!

Thank you - Heather

Private Sub ctlGoTo_Click()

Dim varCriteria As Variant

Const acbcQuote = """"


varCriteria = "PKey = " & Me.Combo83.Value & acbcQuote


Me.RecordSource = "SELECT * FROM sysqryResidentListByZip WHERE " &
varCriteria



ExitHere:
End Sub
 
D

Dirk Goldgar

HLCruz via AccessMonster.com said:
I am trying to change the record source property of my form via code in
VBA,
the code runs in the onclick event of a button.

I'd like for the code to create a criteria based on the selection of a
combo
box. The value will be the record's street address.

The code I'm trying to piece together isn't working - the error I get is
that
there is no such record. But, I happen to know that the record exists so
I
suspect it's my code that is faulty.

Any help would be greatly appreciated!

Thank you - Heather

Private Sub ctlGoTo_Click()

Dim varCriteria As Variant

Const acbcQuote = """"


varCriteria = "PKey = " & Me.Combo83.Value & acbcQuote


Me.RecordSource = "SELECT * FROM sysqryResidentListByZip WHERE " &
varCriteria



ExitHere:
End Sub


It appears you are building a closing quote into your critera string, but
not an opening quote. Try replacing this line:
varCriteria = "PKey = " & Me.Combo83.Value & acbcQuote

.... with this line:

varCriteria = "PKey = " & acbcQuote & Me.Combo83 & acbcQuote
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top