Solved

SQL question

Posted on 2002-05-03
11
151 Views
Last Modified: 2010-05-02
hi can someone please tell me why this statement will not work it works fine when just searching for subdom but will not when using AND Please advise...

Subdom = Request.QueryString("Subdom")
Domain = Request.QueryString("Domain")
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset

   ' Open the connection
   cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
      "Data Source=" & App.Path & "\DDNSHCP.mdb;"
 
   ' Open the recordset
   rst.Open "SELECT * FROM Users WHERE Subdom = '" & Subdom & "' AND Domain = "' & Domain & "'", _
      cnn, adOpenKeyset, adLockOptimistic
0
Comment
Question by:hilltop
  • 5
  • 2
  • 2
  • +1
11 Comments
 
LVL 2

Author Comment

by:hilltop
ID: 6989522
This is being executed from a webclass
0
 
LVL 12

Expert Comment

by:roverm
ID: 6989641
Couple of possibilities:
1. Make sure the query isn't case sensitive:
SELECT * FROM Users WHERE UCase(Subdom) = '" & UCase(Subdom) & "' AND UCase(Domain) = "' & UCase(Domain) & "'" (I am not sure about the UCase in the SQL statement, could be Upper as well).
2. Use the LIKE statement instead of the '=':
SELECT * FROM Users WHERE Subdom LIKE '" & Subdom & "%' AND Domain LIKE "' & Domain & "%'" (make sure to add the percent sign '%')
3. Combine the first 2 options.

D'Mzzl!
RoverM  
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 6989671
rst.Open "SELECT * FROM Users WHERE Subdom = '" & Subdom & "' AND Domain = "' & Domain & "'", _
     cnn, adOpenKeyset, adLockOptimistic

Unless it is a typo you have the quotes backwards between Domain = and & Domain

Should be
rst.Open "SELECT * FROM Users WHERE Subdom = '" & Subdom & "' AND Domain = '" & Domain & "'", _
     cnn, adOpenKeyset, adLockOptimistic

If that is not the problem what error are you getting?  

If you are just not getting any records are you sure records exist for the criteria?

good luck
mlmcc
0
 
LVL 2

Author Comment

by:hilltop
ID: 6989882
No dice when using
rst.Open "SELECT * FROM Users WHERE Subdom = '" & Subdom & "' AND Domain = '" & Domain & "'", _
    cnn, adOpenKeyset, adLockOptimistic

It just pops up the microsoft script debugger no error other than that.

when using
rst.Open "SELECT * FROM Users WHERE Subdom = '" & Subdom & "'", _
      'cnn, adOpenKeyset, adLockOptimistic

it works fine I am at a serios loss here
0
 
LVL 2

Author Comment

by:hilltop
ID: 6989886
new development when using

rst.Open "SELECT * FROM Users WHERE Domain = '" & Domain & "'", _
      cnn, adOpenKeyset, adLockOptimistic

it errors as well this is a field in the Users table any ideas
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 2

Author Comment

by:hilltop
ID: 6989998
I renamed the field Domains and updated my app to reflect the new field name were applicable the AND statment now works fine. Do you have any idea why this happened
0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 50 total points
ID: 6990453
Domain is a reserved word.
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 6990460
You could also have surrounded with square brackets [Domain]
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 6992705
You're right emoreau.  Seems like we overlook the obvious.

mlmcc
0
 
LVL 12

Expert Comment

by:roverm
ID: 6993088
Yeppers....Good one emoreau!
0
 
LVL 2

Author Comment

by:hilltop
ID: 6994098
Thank you very much
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now