Passing a variable from ASP to Access for db query

Results 1 to 2 of 2

Thread: Passing a variable from ASP to Access for db query

  1. #1
    Join Date
    Dec 1969

    Default Passing a variable from ASP to Access for db query

    This is a continuation and refinement of a prior post to the ASP board.<BR><BR>I am new ASP user still working on creating our Corporate Intranet. I am placing the following parameter (?page=xxx) in the url of the page and want to use the "xxx" as a criteria in a query in an access database. In the ASP page the "xxx" parameter is being stored as a variable strPageContent. The trouble I&#039m having is passing the variable to the Access query. The SQL stmt which errors out in Access is as follows:<BR><BR>PARAMETERS strPageContent Text;<BR>SELECT [Navigation Bar].[Security Reqd], [Navigation Bar].ID, [Navigation Bar].[Button Label], [Navigation Bar].[Button URL], [Navigation Bar].Page<BR>FROM [Navigation Bar]<BR>WHERE ((([Navigation Bar].Page)="all" Or ([Navigation Bar].Page)="?strPageContent")) ***THE VARIABLE***<BR>ORDER BY [Navigation Bar].ID;<BR><BR>The SQL query stmt is actually located in the Access db under the query option. The variable strPageContent is defined in the .asp page. The query is looking for the actual string "&strPageContent" rather than the underlying variable. Removing the quote marks around the strPageContent does not have the desired effect.<BR><BR>The asp code is as follows:<BR><BR>&#060;%<BR>Session.timeout = 10<BR>Dim strPageContent, objConn, objRSNavBar, strPage, strSQLNavBar, strSQLBody, objRSBody<BR><BR>if request.servervariables("query_string")&#060;&#062 ;"" then <BR>strPageContent=trim(request.querystring("page" )) ***THIS IS THE VARIABLE I&#039M ATTEMPTING TO SEND TO THE QRYNAV BAR***<BR>Else<BR>strPageContent="error"<BR>End If<BR>%&#062;<BR><BR>&#060;%<BR>If IsObject(Session("mcb_conn")) Then <BR>Set objConn = Session("mcb_conn")<BR>Else<BR>Set objConn = Server.CreateObject("ADODB.Connection")<BR>objConn .open "mcb","",""<BR>Set Session("mcb_conn") = objConn<BR>End If<BR><BR>strSQLNavBar= "qryNavBar" ***THE QRYNAVBAR IS A QUERY BUILT IN ACCESS***<BR><BR>strSQLBody= "qryBody" ***" " " " " " " "***<BR><BR><BR>Set objRSNavBar = Server.CreateObject("ADODB.Recordset")<BR>Set objRSBody = Server.CreateObject("ADODB.Recordset")<BR><BR>objR SNavBar.Open strSQLNavBar, objConn<BR>objRSBody.Open strSQLBody, objConn<BR>%&#062;<BR>

  2. #2
    InstrRev Guest

    Default RE: Passing a variable from ASP to Access for db q

    dim strPageContent<BR>strPageContent = request.querystring("page")<BR><BR>dim strSQL<BR>strSQL = "SELECT [Navigation Bar].[Security Reqd], " &_<BR>"[Navigation Bar].ID, [Navigation Bar].[Button Label], " &_<BR>"[Navigation Bar].[Button URL], [Navigation Bar].Page " &_<BR>"FROM [Navigation Bar] " &_<BR>"WHERE [Navigation Bar].Page=&#039all&#039 " &_<BR>"Or [Navigation Bar].Page=&#039" & strPageContent & "&#039 " &_<BR>"ORDER BY [Navigation Bar].ID; "<BR><BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts