changing cbo rowsource

  • Thread starter Thread starter Junior
  • Start date Start date
J

Junior

I'm trying to learn better code - the code below in a subform Open event
works but i want to improve it -
Also i haven't been able to get it working when the Where code is text vs.an
integer
1. I want to subtitute strWhere for the Where Clause What should the code
look like?
2. If WHERE was a text string - say TlkpReg_Cert.Type="MIT" .What should the
code look like?
Thanks for any help

Dim strPos As String, strWhere As String
strPos = Me.TxtHybPos
StrWhere = "?"
If strPos = "MIT" Then

Me.cboRegCert.RowSource = "SELECT TlkpReg_Cert.RegID, TlkpReg_Cert.RegDesc,
TlkpReg_Cert.RegGrp, TlkpReg_Cert.PrintOrder " _
& "FROM TlkpReg_Cert WHERE (((TlkpReg_Cert.PrintOrder) < 8)) " _
& "ORDER BY TlkpReg_Cert.PrintOrder;"

ElseIf strPos = "DRT" Then
 
If I understand your questions, you should be able to use

Me.cboRegCert.RowSource = "SELECT TlkpReg_Cert.RegID, TlkpReg_Cert.RegDesc,
TlkpReg_Cert.RegGrp, TlkpReg_Cert.PrintOrder " _
& "FROM TlkpReg_Cert " _
& "WHERE " & strWhere & " " _
& "ORDER BY TlkpReg_Cert.PrintOrder;"

To handle text values, you can use single quotes:

Me.cboRegCert.RowSource = "SELECT TlkpReg_Cert.RegID, TlkpReg_Cert.RegDesc,
TlkpReg_Cert.RegGrp, TlkpReg_Cert.PrintOrder " _
& "FROM TlkpReg_Cert WHERE (((TlkpReg_Cert.Type) < 'MIT')) " _
& "ORDER BY TlkpReg_Cert.PrintOrder;"

If your string has apostrophes in it, you need to double them up: rather
than

WHERE (((User.Surname) < 'O'Reilly'))

you'd use


WHERE (((User.Surname) < 'O''Reilly'))
 
Back
Top