Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

invalid use of null error when setting default value of select menu

Status
Not open for further replies.

ringadeal

Technical User
Jan 16, 2008
67
US
The following code which sets the default value of a select menu to equal Session("VendorPartNumber") is causing the error message: "runtime error '800a005e' Invalid use of Null: 'CStr'/.."
Code:
<option value="<%=(Recordset1.Fields.Item("ManufacturerPartNumber").Value)%>"  <%If (Not isNull(Session("VendorPartNumber"))) Then If ((Recordset1.Fields.Item("ManufacturerPartNumber").Value) = CStr(Session("VendorPartNumber"))) Then Response.Write("SELECTED") : Response.Write("")%>></option>
 
You really should consider putting your sessions in a variable, you always want to access your sessions as least as possible.


Try something like this:


<%
Dim strVendorPartNumber

strVendorPartNumber = Session("VendorPartNumber")

If strVendorPartNumber = "" then ....

%>

I think your problem maybe that you are trying to convert to string on this session... if you do this to a variable you should be in the clear....

-Jason


Jason

[red]Army[/red] : [white]Combat Engineer[/white] : [blue]21B[/blue]

 
Ringadeal: the way the code you posted is all jumbled up makes it hard to read.

Code:
Dim sOpt
Do While Not RS1.EoF
  sOpt = "<option value=""" _
       & RS1("ManufacturerPartNumber") _
       & """ "

  If Session("VendorPartNumber") = (RS1("ManufacturerPartNumber") & "") Then 
      sOpt = sOpt & "SELECTED"
  End If 

  sOpt = sOpt & ">" & RS1("ManufacturerPartNumber") _
       & "</option>" & vbCrLf

  Response.Write sOpt
  RS1.MoveNext
Loop
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top