I have a clone macro in a subform table control grid which copies 1 row to a clone table.
It works perfectly if only 1 record. If another record is added, it still just copies the first.
If there are many records and none have been copied and then the macro is run, it will copy
the first record. If macro is run again, it will copy last record.If records are clicked on
is no help. Does anyone know of additional code to be able to make any specific record the active record??
Sub Clone_To_New_Record (oEvent As Object) 'Button > Execute > event
oForm = oEvent.Source.Model.Parent 'SubForm from Button
IF oForm.isNew THEN Exit Sub
oForm.updateRow
iID = oForm.Columns.GetByName("EX").Value
oForm.moveToInsertRow
oStatement = oForm.ActiveConnection.createStatement() 'Create an SQL statement object
sColumns = sColumns & """EX"""
sColumns = sColumns & ", ""ID2"""
sColumns = sColumns & ", ""DESCRIBE"""
sColumns = sColumns & ", ""AMOUNT"""
sSQL = "INSERT INTO ""CLONE2"" (" & sColumns & ") SELECT " & sColumns & " FROM ""EXPLAIN"" WHERE ""EX"" = "
& iID
oStatement.executeUpdate( sSQL ) 'Execute the SQL command
oForm.reload
oForm.last
End Sub
I have looked at various posts that seem to be what I want,
but either none worked or I put them in the wrong place.
They all brought up various problems, but I don't know how
to address them.
Related
I have cruised and implemented code from some of the other responses to this question, but I'm still having no luck. I am still getting the error.
If ((bReport And bIsDate And CheckPermissions("lotsales")) Or Request.QueryString("report")) Then
OpenDB
Dim oRs, sSQL, sSQL2, iCancellations, iSales, sDate, sInitDate, sEndDate, iPhaseID, iPhaseNumber, rowCount
sInitDate = Request("startDate")
sEndDate = Request("endDate")
sSQL = "sp_get_lot_sales_test '" & sInitDate & "', '" & sEndDate & "', " & sPhase & ", '" & sReportView & "'"
'response.write vbNewLine & "<!-- sql: " & sSQL & "-->" & vbNewLine
'response.write sSQL
'response.Flush
Set oRs = ExecuteCommand(sSQL,1)
End If
And then here is where the error occurs -
If (oRs.EOF) Then <-- fails here
Response.Write("<TR><TD ALIGN=""center"">There is no data to report on!</TD></TR>")
Else
Do While Not oRs.EOF
As a last resort I am going to go back to the stored procedure and deconstruct it to make sure all is well there. Does anyone have any insight as to why I might be getting the error? I am not issuing a close anywhere.
Here is the ExecuteCommand function -
Function ExecuteCommand(s,i)
On Error Resume Next
Set ExecuteCommand = oDBc.Execute(s, , i)
End Function
This may be old, but I frequently come across that error (operation is not allowed when object is closed).
What I do is in the stored procedure, I add the follwing:
SET NOCOUNT ON
SET ANSI_WARNINGS OFF
right below the AS in the procedure.
That's all I do and the problem goes away.
I am maintaining some old Classic ASP code for a client, code that we took over from a prior developer, and this bug drove me crazy for 4 hours.
I finally discovered a few PRINT statements in the associated SQL stored procedure, which were there for troubleshooting or checking values but don't actually return rows, yet they caused this to fail:
Set cnContentDB = Server.CreateObject("ADODB.Connection")
cnContentDB2.Open sString
sSQL = "EXEC YourStoredProc"
Set oRS2 = Server.CreateObject("ADODB.Recordset")
oRS2.Open sSQL, cnContentDB
if not oR2.EOF then 'THIS WAS GIVING THE ERROR,
'EVEN THOUGH THE STORED PROC ALWAYS RETURNS RECORDS
I removed the Print statements, and the error went away.
Although this is years old, we still end up here looking for solutions.
The cause of this error for me was that the User did not have Execute permission on the Stored Procedure. Granting Execute permission resolved the error.
You need a connection object.
set conn = server.CreateObject("adodb.connection")
set oRs = conn.execute(sSql)
Let me start off by saying that I am very greatful to have a place to go to when I need help with some code and I'm even more thankful when I see people trying to help out, so for everyone here Thank you for looking at my question/problem even if you don't have an answer.
With that said, on with my question/problem:
I have been trying to get this to work but I cannot seem to find the syntax error!! :-(
Can anyone please help me...
Here is the code:
dim strPathtoCSVFolder,strPathtoCSVFile,strPathtoCSVFileTWO
strPathtoCSVFolder="D:\classic_asp\test\" & Request.QueryString("XTNO") & "\Data\"
strPathtoCSVFile="Unit_" & Request.QueryString("XTNO") & "_Year_" & Request.QueryString("year") & "_Q_" & Request.QueryString("q") & "_MERGE_DataCsv.csv"
strPathtoCSVFileTWO="Unit_" & Request.QueryString("XTNO") & "_Year_" & Request.QueryString("year") & "_Q_" & Request.QueryString("q") & "_MERGE_DataCsv_SORTED.csv"
Set Conn = CreateObject("ADODB.Connection")
Set RS = CreateObject("ADODB.Recordset")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPathtoCSVFolder & ";Extended Properties=""text;HDR=YES;FMT=Delimited"""
dim strDirInfoX
strDirInfoX="SELECT STATE, SUM(GALLONS) as Total FROM " & strPathtoCSVFile & " GROUP BY STATE "
'''''' response.write strDirInfoX
dim strTxttoMem
dim strsource
strsource="RS.Open " & strDirInfoX & " , Conn, 1, 3, &H0001"
RS.Open strsource
'response.write strsource
redim FieldNames(rs.fields.count)
redim FieldTypes(rs.fields.count)
For i = 0 To (rs.Fields.Count - 1)
FieldNames(i) = cstr(trim(rs.Fields.Item(i).Name))
FieldTypes(i) = cstr(trim(rs.Fields.Item(i).Type))
Next
RS.Close
RS.Open strDirInfoX, Conn, 3, 3, &H0001
Do Until RS.EOF
'''' for i=0 to ubound(FieldNames)-1
''' response.write(FieldNames(i) & " = " & RS.Fields.Item(FieldNames(i)) & "<br>")
strTxttoMem=strTxttoMem & RS("STATE") & RS("total")
'' next
RS.MoveNext
Loop
RS.Close
Conn.Close
dim fs,tfile
set fs=Server.CreateObject("Scripting.FileSystemObject")
set tfile=fs.CreateTextFile(strPathtoCSVFolder & strPathtoCSVFileTWO)
tfile.WriteLine(strTxttoMem)
tfile.close
set tfile=nothing
set fs=nothing
Thank you so much for any help...
Well, without running your code, I spotted an error in this part:
dim strsource
strsource="RS.Open " & strDirInfoX & " , Conn, 1, 3, &H0001"
RS.Open strsource
or to shorten it, you are doing this:
RS.Open "RS.Open " & strDirInfoX & " , Conn, 1, 3, &H0001"
change it to RS.Open strDirInfoX, Conn, 1, 3, &H0001 and that part will run better.
This is almost impossible to answer, there could be multiple errors and much depends on what is declared before, eg an option explicit makes a huge difference (and is advisable).
Since debugging in the browser is difficult at best, you copy this code - that comes from an asp file i guess - and put it in a vbs script, replace the response.write with wscript.echo and run the code.
Then you get an error at some line, correct it and so on, afterward replace the echos's by response.write's and you'r done.
I also recommend useing Firefox and the Firebug plugin to do your testing, you will get more debugging info there, at least use the developer view in Chrome or IE
Success..
Been some time working on VBScript but shouldnt tfile.close be tfile.Close?
Did you try reading the file as a text file rather than connecting to it with an ADODB connection? Since it is a CSV file, you might be able to read it as a plain text file. You can split the content with comma and loop and get what you want.
If you want to access it using ADODB connection, try saving the file with an xlsx extention(Either copy the contents through code or save it manually. The same code might work).
Shamelessly adding a link to my blog on ADO
http://www.blogger.com/blogger.g?blogID=3033014869583885023#editor/target=post;postID=8274119342550879092
I have this same type of loop running on several pages, but the one that I said I'd get done in 1 day just... Ignores the out.movenext and prints only the first result out of a possible 10 results until it crashes. The SQL is fine. I got it with a tracer.
Changes:
I originally had the movenext last before the loop - but moved it up one line for tracing. Tried (out = out.movenext , out = out.next) to see if it would do anything. And I tried putting an integer count in to have it stop after 20 loops so I can debug it faster. The int changes, the data prints, but out doesn't advance.
strSQL = "SELECT [RecordID],[SubmitDate],[DataEntered] FROM [ManagerFileReview] where submitdate = '" & timetap & "'"
out = cnt.execute(strSQL)
out.movefirst
response.write "<table>"
Do while not out.eof
response.write "<tr><td>"
response.write "<table><thead></thead>"
response.write "<tr><td>Submit Date:</td><td>" & out(1) & "</td></tr>"
response.write "<tr><td>Data Entered:</td><td>" & out(2) & "rrrrrrrrrrr</td></tr>"
out.movenext
response.write "passed movenext</table></td></tr>"
loop
response.write "</table>"
Edit: Forgot the "SET" before the cnt.execute
The logic looks OK, unless I'm missing something. Even though out isn't listed as a reserved word with MS, I do wonder if it's the problem.
Found it.
Didn't have SET before the out = cnt.execute(strSQL)
Should have been
set out = cnt.execute(strSQL)
After long time looking for a solution I found one here - I thought....
The code I tried to implement was:
If DetailsView1.Rows.Count > 0 Then
Dim row As DetailsViewRow
For Each row In DetailsView1.Rows
TextBox3.Text &= row.Cells(0).Text & " = " & row.Cells(1).Text & " "
Next
Else
TextBox3.Text = "No data found"
End If
As result I only got the line label. The row.Cells(1) did not return any data.
My DetailView show correct data from my database (total 7 lines). I need to merge these data together with some other user input fields and create an output file.
My questions are:
1) How do I get the detailview data into a textbox
2) My final task is to create an output.txt file
I have to use VB since I'm unfamilar with C#.
I am writing Classic ASP program.In one function, I have to use 2 update statements to one table in one function. First Statement is update the quantity of invoice and second update statement is base on that update Purchase Order quantity and Purchase Requisition quantity, I need to update one flag field. Can I write in same function as following:
SET RS = app.Execute("SELECT PRInvoiceNo, Quantity FROM PurchaseOrderDetails WHERE CoID='" & param & "'")
do while RS.EOF=false
app.Execute("UPDATE PurchaseRequisitionDetails SET PO_Quantity = PO_Quantity + " & RS("Quantity") & " WHERE CoID='" & param & "' AND PRInvoiceNo = '" & RS("PRInvoiceNo") & "'")
app.Execute("UPDATE PurchaseRequisitionDetails SET FullyPaidFlag=CASE WHEN PO_Quantity >= Quantity THEN 1 ELSE 0 END WHERE CoID='" & param & "' AND PRInvoiceNo = '" & RS("PRInvoiceNo") & "'")
RS.MoveNext
loop
The problem is in the loop the first statement is properly worked. Second one not work. What can it be? Can I do like this or not?
Well, I have to go, but be sure to check the following:
Response.Write(RS.RecordCount) -- are there any records? Or, do a Response.Write("hello") inside the loop to make sure.
Check that RS("Quantity"), param, etc are not null. If they are, your string concatenation will result in a null string.
Also, please, please don't forget to escape your variables!
Replace(param, "'", "''")
Good night!