Adding formula to Vba - formula

I want to add this formula =MID(C2,SEARCH("",C2)+10,SEARCH("+",C2)-SEARCH("",C2)-10) to the end of formatting code so that it populates column "d" down to the last row
The code i created from record macro:
sub Update()
Cells.Select
Cells.EntireColumn.AutoFit
Columns("C:H").Select
Selection.Delete Shift:=xlToLeft
Columns("C:C").Select
Selection.Cut
Columns("B:B").Select
Selection.Insert Shift:=xlToRight
Columns("D:D").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("E:AK").Select
Selection.Delete Shift:=xlToLeft
Range("D1").Select
ActiveCell.FormulaR1C1 = "Times"
Range("F1").Select
ActiveCell.FormulaR1C1 = "Room"
Columns("G:G").Select
Columns("F:F").EntireColumn.AutoFit
Columns("K:L").Select
Selection.Delete Shift:=xlToLeft
Columns("M:X").Select
Selection.Delete Shift:=xlToLeft
Columns("N:Q").Select
Selection.Delete Shift:=xlToLeft
Columns("L:L").Select
Selection.Cut
Columns("I:I").Select
Selection.Insert Shift:=xlToRight
Columns("M:M").Select
Selection.Cut
Columns("K:K").Select
Selection.Insert Shift:=xlToRight
Columns("P:P").Select
Selection.Cut
Columns("M:M").Select
Selection.Insert Shift:=xlToRight
Columns("P:P").Select
Selection.Cut
Columns("N:N").Select
Selection.Insert Shift:=xlToRight
Columns("P:P").Select
Selection.NumberFormat = "0"
Cells.Select
Range("H1").Activate
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("A1:P40").Select
ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$P$40"), , xlYes).Name = _
"Table1"
Range("Table1[#All]").Select
ActiveSheet.ListObjects("Table1").TableStyle = "TableStyleMedium2"
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Columns("G:G").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("Table1[[#Headers],[Column1]]").Select
ActiveCell.FormulaR1C1 = "Outcome"
End Sub
This code works really well in formatting the excel sheet I have but I would like to go that one step further and include this little bit of code, however the number of rows varies but will rarely exceed 40
I'd be really appreciate some help or/and advice, thank you in anticipation

Add this just before End Sub. Because you are have a table formatted already, it will automatically fill in each cell.
Range("D2").FormulaR1C1 = "=MID(RC[-1],SEARCH("""",RC[-1])+10,SEARCH(""+"",RC[-1])-SEARCH("""",RC[-1])-10)"

Related

ASP.NET MS chart control: Data points insertion error. Only 2 Y values can be set for this data series. Parameter name: dataSource

I'm getting this error on my MS Chart control:
Data points insertion error. Only 2 Y values can be set for this data series.
Parameter name: dataSource
It occurs on line chartPriceHistory_STATIC.DataBind() in my code below.
I think it has got something to do with the way I'm adding points (AddXY) but can't figure out what it is.
I tried these 2 code options:
Option 1
chartPriceHistory_STATIC.Series(seriesName).Points.AddXY(get3LetterMonth(CDate(row("createdate")).Month) + "-" + CDate(row("createdate")).Year.ToString, {CType(row("price"), Integer), totalobjects})
Option 2
chartPriceHistory_STATIC.Series(seriesName).Points.AddXY(get3LetterMonth(CDate(row("createdate")).Month) + "-" + CDate(row("createdate")).Year.ToString, CType(row("price"), Integer))
chartPriceHistory_STATIC.Series("totalobjects").Points.AddXY(get3LetterMonth(CDate(row("createdate")).Month) + "-" + CDate(row("createdate")).Year.ToString, totalobjects)
Both throw the same error...what am I missing?
Dim mycommand As New SqlCommand("SELECT avgprice, createdate, totalobjects FROM avgprices", myConnection)
Dim dtPrices As New System.Data.DataTable
dtPrices.Columns.Add("price", System.Type.GetType("System.Int32"))
dtPrices.Columns.Add("createdate", System.Type.GetType("System.DateTime"))
dtPrices.Columns.Add("totalobjects", System.Type.GetType("System.Int32"))
Dim dr As System.Data.DataRow
Try
Dim reader As SqlDataReader = mycommand.ExecuteReader()
While reader.Read
dr = dtPrices.NewRow()
dr("price") = reader("price")
dr("createdate") = reader("createdate")
dr("totalobjects") = reader("totalobjects")
dtPrices.Rows.Add(dr)
End While
Catch ex As Exception
End Try
' Initializes a New instance of the DataSet class
Dim myDataSet As DataSet = New DataSet()
'Adds rows in the DataSet
myDataSet.Tables.Add(dtPrices)
chartPriceHistory_STATIC.Series.Clear()
Dim seriesName As String = "Avg price"
chartPriceHistory_STATIC.Series.Add(seriesName)
chartPriceHistory_STATIC.Series(seriesName).XValueMember = "Date"
chartPriceHistory_STATIC.ChartAreas.Add("ChartArea1")
chartPriceHistory_STATIC.Series(seriesName).YValuesPerPoint = 2
chartPriceHistory_STATIC.ChartAreas(0).AxisY.MajorGrid.Enabled = True
chartPriceHistory_STATIC.ChartAreas(0).AxisY.Title = "Price"
Dim totalobjects As Integer = 1
chartPriceHistory_STATIC.Series.Add("Series2")
chartPriceHistory_STATIC.Series("Series2").YAxisType = AxisType.Secondary
chartPriceHistory_STATIC.Series("Series2").XValueMember = "Date"
chartPriceHistory_STATIC.Series("Series2").YValueMembers = "totalobjects"
chartPriceHistory_STATIC.Series("Series2").Name = "totalobjects"
chartPriceHistory_STATIC.Series("totalobjects").ChartType = SeriesChartType.Line
chartPriceHistory_STATIC.Series("totalobjects").ToolTip = "Total objects"
chartPriceHistory_STATIC.Series(0).YAxisType = AxisType.Primary
chartPriceHistory_STATIC.Series(1).YAxisType = AxisType.Secondary
For Each row As DataRow In myDataSet.Tables(0).Rows
totalobjects += 1
'I tried: these 2 options, both generate the same error
chartPriceHistory_STATIC.Series(seriesName).Points.AddXY(get3LetterMonth(CDate(row("createdate")).Month) + "-" + CDate(row("createdate")).Year.ToString, {CType(row("price"), Integer), totalobjects})
chartPriceHistory_STATIC.Series(seriesName).Points.AddXY(get3LetterMonth(CDate(row("createdate")).Month) + "-" + CDate(row("createdate")).Year.ToString, CType(row("price"), Integer))
chartPriceHistory_STATIC.Series("totalobjects").Points.AddXY(get3LetterMonth(CDate(row("createdate")).Month) + "-" + CDate(row("createdate")).Year.ToString, totalobjects)
Next
chartPriceHistory_STATIC.DataSource = myDataSet
chartPriceHistory_STATIC.DataBind()
You need to set the YValueMembers for the "Avg price" series, too.
Add this line (use whatever string you want to plot on Y axis):
chartPriceHistory_Static.Series(seriesName).YValueMembers = "totalobjects"
Add it just before this line:
chartPriceHistory_Static.Series(seriesName).YValuesPerPoint = 2
Also, your name of date/createdate column is inconsistent - you won't see the plots until you correct that.
If you are only adding 1 YValue, you can reduce the YValuesPerPoint down to 1 again, without error.
Tested. Works fine. Cheers!
Instead of using Points.AddXY method try to create point through new class and add them to chart
foreach (var result in data)
{
point = new DataPoint();
point.AxisLabel = result.XData;
point.YValues = new double[] { result.YData };
point.Color = result.Color;
seriesDetail.Points.Add(point);
}

Access - Strange Error with Date Function

This is a strange bug and I feel like I'm missing something easy.
When I use the standard access date function on one form it works without issue (see 'functions properly'). When I use it on another form (see 'code causing error') I get a debug error 'Database can't find the field 'Date' referred to in your expression.'
Hoping someone else sees a stupid/obvious mistake...
Functions properly:
With rs
.AddNew
If chkSubAssembly = True Then
.Fields("Document") = mySubassembly
.Fields("Type") = "S"
Else
.Fields("Document") = "M" & cmbCustomer & "-" & txtCustPN
.Fields("Type") = "D"
End If
.Fields("Description") = txtDMRDesc
.Fields("Author") = Forms("frmUser").lblUser.Caption
.Fields("CreationDate") = date
.Fields("Revision") = "Draft"
.Fields("PE") = cmbPE.Column(1)
.Fields("lasteditby") = Forms("frmUser").lblUser.Caption
.Update
End With
Code Causing Error:
With rs
.AddNew
.Fields("ValidNum") = myProtocol
.Fields("Description") = txtNewDescription
.Fields("Author") = Forms("frmUser").lblUser.Caption
.Fields("createdOn") = date
.Fields("lasteditby") = Forms("frmUser").lblUser.Caption
.Update
End With

ExecuteNonQuery throws ORA-1722 in Oracle Number type

I have this Table "T" in Oracle 11g(11.2.0.1.0).
CD NVARCHAR2(20) Primary Key
,VAL NUMBER(1)
When Update, It's throws ORA-1722.
_factory = DbProviderFactories.GetFactory("Oracle.DataAccess.Client")
...(Createconnection, CreateAdapter,CreateCommand, Transaction)
_command.CommandText="UPDATE T SET VAL = :VAL WHERE CD = :CD"
dim p1 as DbParameter = _command.CreateParameter()
p1.DbType = DbType.String
p1.Value = "AX-0001"
p1.ParameterName = "CD"
_command.Parameters.Add(p1)
dim p2 as DbParameter = _command.CreateParameter()
p2.DbType = DbType.Decimal
p2.Value = 3
p2.ParameterName = "VAL"
_command.Parameters.Add(p2)
_command.ExecuteNonQuery() ' ->throw exception
But, Select query returned correct DataTable.
_factory = DbProviderFactories.GetFactory("Oracle.DataAccess.Client")
...(Createconnection, CreateAdapter,CreateCommand, Transaction)
_command.CommandText="SELECT CD, VAL FROM T WHERE CD = :CD AND VAL = :VAL"
dim p1 as DbParameter = _command.CreateParameter()
p1.DbType = DbType.String
p1.Value = "AX-0001"
p1.ParameterName = "CD"
_command.Parameters.Add(p1)
dim p2 as DbParameter = _command.CreateParameter()
p2.DbType = DbType.Decimal
p2.Value = 3
p2.ParameterName = "VAL"
_command.Parameters.Add(p2)
_adapter.SelectCommand = _command
_command.ExecuteNonQuery() ' ->success
what I wrong?
I tried to modify CreateParameter to New OracleParameter and DbType to OracleDbType, but it throws ORA-1722 too.
Add more...(1/20 02:04 GMT)
I set more parameters "Size", "Precision", "Scale" by my function, but it's not yet resolved throws ORA-1722.
AddDecimalParam("VAL", 3, 1,0)
Public Overridable Sub AddDecimalParam(name As String, value As Object, precision As Byte, scale As Byte)
Dim p As DbParameter = _command.CreateParameter()
p.ParameterName = name
p.DbType = DbType.Decimal
p.Value = value
p.Size = precision + scale
p.Precision = precision ' -> can't change value! keep "0".
p.Scale = scale
p.Direction = ParameterDirection.Input
_command.Parameters.Add(p)
End Sub
In this way, I get same result.
AddOraDecimalParam("HANBAISAKI_MONEY", row("HANBAISAKI_MONEY"), 1, 0)
Public Overridable Sub AddOraDecimalParam(name As String, value As Object, precision As Byte, scale As Byte)
Dim p As Oracle.DataAccess.Client.OracleParameter = New OracleParameter(name, OracleDbType.Decimal, precision + scale, ParameterDirection.Input, True, precision, scale, name, DataRowVersion.Proposed, Nothing)
p.Value = value
_command.Parameters.Add(p)
End Sub
I resolved this probrem.
ODP.NET use parameters order of decralation not name in default.
I must set "command.BindByName" is true.
I modified my DbUtility.
Protected _factory As System.Data.Common.DbProviderFactory
Protected _connection As DbConnection = Nothing
Protected _adapter As DbDataAdapter = Nothing
Protected _command As DbCommand = Nothing
Public Sub New(target as String)
_factory = System.Data.Common.DbProviderFactories.GetFactory(target)
_connection = _factory.CreateConnection()
_connection.ConnectionString = DbConfig.getIns().ConnectionString
_connection.Open()
_adapter = _factory.CreateDataAdapter
_command = _connection.CreateCommand
_command.CommandType = CommandType.Text
If TypeOf _command Is OracleCommand Then
DirectCast(_command, OracleCommand).BindByName = True
End If
End Sub
thank you.

How to insert a new row between another rows in gridview boundfield?

I have a gridview like below picture:
In this gridview I want to introduce a new row that does not have any completely out of the cell where the last "Grand Total" there to put a variable mine.
But the question is, how introduce a new row among others?
My code is:
Dim Qty As Double = 0
Dim CostCategory As Double = 0
Dim AssemblyDate As String = Nothing
If GridView1.Rows.Count <> 0 Then
For x As Integer = 0 To GridView1.Rows.Count - 1
For y As Integer = 0 To GridView1.Columns.Count - 1
If y = 0 And GridView1.Rows(x).Cells(1).Text = AssemblyDate Then
GridView1.Rows(x).Cells(1).Text = ""
End If
If GridView1.Rows(x).Cells(1).Text <> Nothing Then
AssemblyDate = GridView1.Rows(x).Cells(1).Text
End If
If y = "9" Then
Qty = Convert.ToDouble(GridView1.Rows(x).Cells(9).Text)
End If
If y = "13" Then
CostCategory = Convert.ToDouble(GridView1.Rows(x).Cells(13).Text)
End If
If y = "14" Then
GridView1.Rows(x).Cells(14).Text = Qty * CostCategory
GridView1.Rows(x).Cells(14).HorizontalAlign = HorizontalAlign.Center
End If
If GridView1.Rows(x).Cells(y).Text = "Yes" Then
GridView1.Rows(x).Cells(y).BackColor = System.Drawing.Color.LawnGreen
ElseIf GridView1.Rows(x).Cells(y).Text = "No" Then
GridView1.Rows(x).Cells(y).BackColor = System.Drawing.Color.Red
End If
Next
Next
End if
before that code i have a query where i fill my gridview:
Dim myQuery As String = SelectQuery & WhereQuery
SqlDataSource1.SelectCommand = myQuery
SqlDataSource1.DataBind()
GridView1.DataSourceID = "SqlDataSource1"
GridView1.DataBind()
Thanks a lot!
Try using this
DataRow dr = tblTable.NewRow(); //Create New Row
dr["ColumnName"] = "Legs"; // Set Column Value
tblTable.Rows.InsertAt(dr, 11); // InsertAt specified position
For VB.Net Grid View
Dim rowNumber As Integer = dGrid.CurrentCell.RowNumber() + 1
Dim myNewRow As DataRow = myDataTable.NewRow()
myDataTable.Rows.InsertAt(myNewRow, rowNumber)
myDataTable.AcceptChanges()

Multiple "If Then Else" in "Do While Not" loop not working, but they do singularly

OK so here is what's pulling my hair out ! I have a page which reads records from a table in one DB, manipulates the data slightly, then writes it to another DB.
In the Do While Not EOF loop, I have a number of If Then Else statements to manipulate the data.
If I run the code in full, most of the If Then Else do not work, if I run the page with just each one in there, they work fine.
I have spent 8 hrs+ working on this and am still baffled
Dim rsndb, fieldstr1, fieldstr2, fieldstr3, fieldstr4, fieldstr5, fieldstr6, fieldstr7, fieldstr8, fieldstr9, fieldstr10, fieldstr11, fieldstr12, fieldstr13, fieldstr14, fieldstr15
recordstr = 0
'##### Empty temp table #####
Set Connection = Server.CreateObject("ADODB.Connection")
Connection.Open "DSN=website"
cSql = "DELETE FROM newtandltest"
Connection.Execute (cSql)
Connection.Close
Set Connection = Nothing
' Select Records From House Database
Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DSN=newdatabase;UID=Intranet;Pwd=password;"
Set rsndb = Server.CreateObject("ADODB.Recordset")
strSQL="Select top 500 VendorTransaction.VendorNo As propvendor, Resort.ResortCode As rid, Resort.ResortName As resname, Locations.LocationName As proploc, Country.CountryCode As propcountry, Season.SeasonDesc As propsea, Property.SeasonDesc As propextrasea, Property.Size As psize, Property.Occupancy As occ, FloatingPoints.FloatingPointsName As TAOLF, Property.StartWeek As propsw, Property.EndWeek As propew, Property.Weeks As propweeks, Property.Points As proppoints, Property.WebPricePW As webprice, Property.Priority As priority, Property.OpenToOffer As offers, Property.PoAOffer As poa, Property.RentalPW As rentalpw, Property.WebDate As webdate"
strSQL = strSQL & " From Property Inner Join Resort On Property.ResortId = Resort.Id Inner Join Country On Resort.CountryId = Country.Id Inner Join Locations On Resort.LocationId = Locations.Id Inner Join FloatingPoints On Property.FloatPointId = FloatingPoints.Id Inner Join PropertyStatus On Property.StatusId = PropertyStatus.Id Inner Join PropertyType On Property.TypeId = PropertyType.Id Inner Join Season On Property.SeasonId = Season.Id Inner Join VendorTransaction On VendorTransaction.propertyId = Property.Id Where (Property.WebDate >= DateAdd(day, -187, GetDate()) And Property.StatusId = 4 and year(Property.WebDate) <> 9999)"
rsndb.Open strSQL, adoCon
Set adoCon1 = Server.CreateObject("ADODB.Connection")
adoCon1.Open "DSN=website"
Do While not rsndb.EOF
'------------------------------------------------------------------------------------------------------------------
fieldstr1 = rsndb("webdate")
'------------------------------------------------------------------------------------------------------------------
fieldstr2 = rsndb("propvendor")
'------------------------------------------------------------------------------------------------------------------
fieldstr3 = rsndb("propcountry")
If rsndb("proploc") = "FLOR" Then
fieldstr3 = rsndb("proploc")
End If
If rsndb("proploc") = "MADE" Then
fieldstr3 = rsndb("proploc")
End If
If rsndb("propcountry") = "ESC" Then
fieldstr3 = rsndb("propcountry") & left(rsndb("proploc"),1)
End If
'------------------------------------------------------------------------------------------------------------------
resnamestr = replace(rsndb("resname"),chr(13)," ")
resnamestr = replace(rsndb("resname"),chr(34),"")
resnamestr = replace(rsndb("resname"),"'","")
fieldstr4 = resnamestr
'------------------------------------------------------------------------------------------------------------------
fieldstr5 = rsndb("propsea")
If len(rsndb("propextrasea")) > 3 Then
fieldstr5 = rsndb("propextrasea")
End If
If rsndb("propcountry") = "POIN" Then
fieldstr5 = ""
End If
'------------------------------------------------------------------------------------------------------------------
fieldstr6 = ""
'------------------------------------------------------------------------------------------------------------------
fieldstr7 = rsndb("propweeks")
If rsndb("propcountry") = "POIN" Then
fieldstr7 = rsndb("proppoints")
End If
'------------------------------------------------------------------------------------------------------------------
If rsndb("propsw") = rsndb("propew") Then
fieldstr8 = rsndb("propsw")
End If
If rsndb("propcountry") = "POIN" Then
fieldstr8 = "POINTS"
fieldstr9 = "n/a"
End If
If rsndb("propsw") < rsndb("propew") Then
fieldstr8 = rsndb("propsw") & "/" & rsndb("propew")
End If
If rsndb("TAOLF") = "F" Then
fieldstr8 = "FLOATING"
End If
'------------------------------------------------------------------------------------------------------------------
tempsize = rsndb("psize")
Select Case tempsize
Case 1
fieldstr9 = "Studio" & " - " & rsndb("occ")
Case 2
fieldstr9 = "1 Bedroom" & " - " & rsndb("occ")
Case 3
fieldstr9 = "2 Bedroom" & " - " & rsndb("occ")
Case 4
fieldstr9 = "3 Bedroom" & " - " & rsndb("occ")
Case 5
fieldstr9 = "4 Bedroom" & " - " & rsndb("occ")
End Select
'------------------------------------------------------------------------------------------------------------------
fieldstr10 = rsndb("rid")
'------------------------------------------------------------------------------------------------------------------
fieldstr11 = rsndb("rid")
'------------------------------------------------------------------------------------------------------------------
fieldstr12 = ""
'------------------------------------------------------------------------------------------------------------------
fieldstr13 = "N"
'------------------------------------------------------------------------------------------------------------------
fieldstr14 = rsndb("webprice")
If rsndb("offers") = 1 Then
fieldstr14 = "Offers"
End If
If rsndb("poa") = 1 Then
fieldstr14 = "POA"
End If
'------------------------------------------------------------------------------------------------------------------
fieldstr15 = rsndb("rentalpw")
lCount = lCount + 1
Set Connection1 = Server.CreateObject("ADODB.Connection")
Connection1.Open "DSN=website"
cSql = "INSERT INTO newtandltest(datefield, field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, price, bargainprice)"
cSql = cSql & "VALUES('"&fieldstr1&"','"&fieldstr2&"','"&fieldstr3&"','"&fieldstr4&"','"&fieldstr5&"','"&fieldstr6&"','"&fieldstr7&"','"&fieldstr8&"','"&fieldstr9&"','"&fieldstr10&"','"&fieldstr11&"','"&fieldstr12&"','"&fieldstr13&"','"&fieldstr14&"','"&fieldstr15&"');"
Connection1.Execute (cSql)
Connection1.Close
Set Connection1 = Nothing
rsndb.MoveNext
Loop
rsndb.Close
adoCon.Close
Set rsndb = Nothing
Set adoCon = Nothing
I am with Shadow Wizard. Tidy up your code, only use rsndb once for every key. And use a dictionary to store your fields with reasonable names. As it is now, it is not maintainable: How should someone know what fieldStr12 stands for?
There is one real bug I spotted: You do three times a replace on the original string, so effectively only the last replace will be visible.
Suggestion how to tidy your code:
Do While not rsndb.EOF
Set fld = createObject("Scripting.Dictionary")
fld.Add "webdate", rsndb("webdate")
fld.Add "propvendor", rsndb("propvendor")
fld.Add "propcountry", rsndb("propcountry")
' etc...
Select Case fld("proploc")
Case "FLOR" fld("propcountry") = fld("proploc")
Case "MADE" fld("propcountry") = fld("proploc")
End case
If fld("propcountry") = "ESC" Then
fld("propcountry") = fld("propcountry") & left(fld("proploc"),1)
End If
' This part is not correct, it is only replacing the ' by an empty string
'resnamestr = replace(rsndb("resname"),chr(13)," ")
'resnamestr = replace(rsndb("resname"),chr(34),"")
'resnamestr = replace(rsndb("resname"),"'","")
'fieldstr4 = resnamestr
fld("resname") = replace(fld("resname"), chr(13), " ")
fld("resname") = replace(fld("resname"), chr(34), "")
fld("resname") = replace(fld("resname"), "'", "")
' etc...
Set Connection1 = Server.CreateObject("ADODB.Connection")
Connection1.Open "DSN=website"
cSql = "INSERT INTO newtandltest(datefield, field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, price, bargainprice)"
' the Items property of a dictionary is an array in the same order that you add them to the dictionary
' You could do the same with the Keys property.
cSql = cSql & "VALUES('" & join(fld.Items, "','") & "');"
Connection1.Execute (cSql)
Connection1.Close
Set Connection1 = Nothing
rsndb.MoveNext
Loop
Something u can improve in your code.
1) You have open connection before while loop so you do not need to open it again in While loop it should be remove
Set Connection1 = Server.CreateObject("ADODB.Connection")
Connection1.Open "DSN=website
While loop ...
WEND
Connection1.Close
Set Connection1 = Nothing
2) check Null and blank before replacing with some value.
for e.g
if(fld("resname") <> "" AND NOT ISNULL(fld("resname")))
replace(fld("resname"), chr(13), " ")
end if
- Note track loop with default value like response.write ("hello") and check in which row loop is breaking and by which cause
The only thing that I can see that might cause this is reading the same field more than once; with certain types of fields (e.g. Memo field of Access) it might become blank after the first read.
To fix such problem you need to read each field once, and store it into local variable:
Do While not rsndb.EOF
curPropLoc = rsndb("proploc")
curPropCountry = rsndb("propcountry")
'...
fieldstr3 = curPropCountry
If curPropLoc = "FLOR" Then
fieldstr3 = curPropLoc
End If
If curPropLoc = "MADE" Then
fieldstr3 = curPropLoc
End If
'...keep using curPropLoc instead of rsndb("proploc") throughout the loop...
'...keep using curPropCountry instead of rsndb("propcountry") throughout the loop...
'......
rsndb.MoveNext
Loop

Resources