AM I using DO WHILE NOT and EOF in VBscript Properly - sql-server-2008

Finally the administrator configured the IIS for me the error message is listed below.
Set SQLStream = CreateObject("ADODB.Stream")
Set SQLConnection = CreateObject("ADODB.Connection")
Set SQLCommand = CreateObject("ADODB.Command")
Set SQLRecordSet = CreateObject("ADODB.RecordSet")
SQLConnection.Open "Provider=sqloledb;SERVER=SQLPROD;DATABASE=MyDataBase;UID=MyUsername;PWDMyPassword;"
'Response.Write("Connection Status: " & SQLConnection.State) & vbnewline
'Response.Write("Connection Provider: " & SQLConnection.Provider) & vbnewline
'Response.Write("Version: " & SQLConnection.Version) & vbnewline
SQLCommand.ActiveConnection = SQLConnection
SQLCommand.CommandText = "SELECT Seminars.Year, Seminars.SeminarID, Seminars.Theme, Seminar_Week.First, Seminar_Week.Last, Seminar_Week.WeekID, Seminar_Week.Date, Seminar_Week.Affiliation FROM Seminars CROSS JOIN Seminar_Week"
'Response.Write("SQL Command Passed in: " & SQLCommand.CommandText)
Set adoRec = SQLCommand.Execute()
file1 = "./seminars/" & seminar_type & "/" & seminar_year & "/" & adoRec("Date") & "-" & adoRec("Year") & "_" & adoRec("Last") & ".pdf"
file2 = "./seminars/" & seminar_type & "/" & seminar_year & "/" & adoRec("Date") & "-" & seminar_year & "_" & adoRec("Last") & "(handouts).pdf"
file3 = "./seminars/" & seminar_type & "/" & seminar_year & "/" & adoRec("Date") & "-" & seminar_year & "_" & adoRec("Last") & "_Flyer.pdf"
Set fso = CreateObject("scripting.filesystemobject")
Response.Write("<p style=" & "margin-left:10px;" & "><img src=" & "./img/right_arrowblue.png" & " alt=" & "Expand/Collapse" & " id=" & "arrow_" & adoRec("Week") & " /><strong>[" & adoRec("Date") & "]</strong> " & ""&aroRec("First") & adoRec("Last") & ", " & adoRec("Affiliation") & "</p>")
The very last line of code causes this error
ADODB.Recordset error '800a0cc1'
Item cannot be found in the collection corresponding to the requested name or ordinal.
FilePath, line 244
Line 244 is the very last line of code that should write Some information about each seminar on the webpage.
I'm pretty sure at this point I am pointing to an incorrect file path because I have an extra space somewhere in all the different string.
My question now is Would the ones in the very beginning, meaning the ones used in
"<p style=" & "margin-left:10px;" & "><img src=" & "./img/right_arrowblue.png"
be causing the trouble.
I'm also unfamiliar with using the "Expand/collapse" so if someone could tell me a little more about that. I am trying to fix someone elses code so I am a little behind the 8 ball.

One small step to a solution:
Your SQL
"SELECT * FROM Seminars WHERE [SeminarID] = 5 ORDER BY DESC"
is definitely wrong: ORDER BY needs (at least) a column name: ORDER BY [SeminarID] DESC.
If that does not solve all your problems, we'll have to think about a step by step approach.
If you get errors, tell us about them (number, description, line). That's what I meant, when I ask you to publish them. If you can't better info than "There was an error when processing the URL" from IIS, then you have to write some command line script to get the database related code absolutely right.
Start with experiments.vbs:
Dim sCS : sCS = !your connection string!
Dim oCN : Set oCN = CreateObject("ADODB.Connection")
oCN.Open sCS
WScript.Echo "CN open:", oCN.State
Dim sSQL : sSQL = !your SQL statement!
Dim oRS : Set oRS = oCN.Execute(sSQL)
WScript.Echo "RS EOF:", CStr(oRS.EOF)
WScript.Echo "Frs Col:", oRS.Fields(0).Name, oRS.Fields(0).Type
Dim i : i = 0
Do Until oRS.EOF
WScript.Echo i, oRS.Fields(0).Value
i = i + 1
oRS.MoveNext
Loop
oCN.Close
and run it in a command window (DOS box): cscript experiments.vbs. This should get you either some lines like:
CN open: 1
RS EOF: False
Frs Col: Id 3
0 ...
1 ...
2 ...
or a focused/publishable error message like:
... .vbs(2465, 14) Microsoft OLE DB Provider for SQL Server: Falsche Syntax in der Nä
he des 'DESC'-Schlüsselworts.
(bad syntax near DESC), which got when I tried the statement
"SELECT * FROM Alpha ORDER BY DESC"

RS.MoveNext
Put the above code on the line before the Loop keyword to avoid an infinite loop.

Are you missing the loop keyword at the end of your loop block?
Check the syntax here: http://msdn.microsoft.com/en-us/library/eked04a7.aspx

Related

ms access error 3061 - To Few Parameters

I'm very new to coding and ms acess, so I really need your help.
I'm trying to get a button to update some data in a table.
I used this code but I keep getting this 3061 error, and i'm going crazy :( help!
Private Sub Concluido_Click() 'Add
CurrentDb.Execute "UPDATE OFP_tempos " & _
" SET Id=" & Me.txtId & _
", Tempo_total='" & Me.txtTotal & "'" & _
", Fim='" & Me.txtHora & "'" & _
" WHERE OFP_tempos=" & Me.txtId.Tag
' disable button edit
Me.Concluido.Enabled = False
End Sub
OK so I found the error at last!
(Now I feel stupid for asking -.-')
On the last line I had the name of the table OFP_tempos instead of the ID -.-'

Access SaveAs function with database data

I'm trying to save a template on a specific place. For example, if a product have the GnrSerie = 1000, it should go to that folder, and then the if the Gnr = E2000, it should go to that folder and then name the file GnrSerie + "-" + Gnr.
I use the following code to save the file:
.SaveAs "CAN'T SHOW THIS\" & rst![GnrSerie] & "\" & rst![Gnr] & "\" & rst![GnrSerie] & "-" & rst![Gnr], wdFormatDocument
Further more, I am connected to the databases/tables where GnrSerie and Gnr is placed
Dim rst As DAO.Recordset
Dim sql As String
Dim db As Database
Set db = CurrentDb
sql = "SELECT * FROM Projektdata WHERE Sagsnr Like '*" & Forms!Sag_Form!SagNr & "*'"
Set rst = db.OpenRecordset(sql, dbOpenDynaset)
When I run it, it just pops up and ask me where I want to save the file.
You probably will have to specify the drive as well:
.SaveAs "D:\CAN'T SHOW THIS\" & rst![GnrSerie] & "\" & rst![Gnr] & "\" & rst![GnrSerie] & "-" & rst![Gnr], wdFormatDocument

DoCmd.RunSQL mySql got Run-time error '3464'

I have this simple code of vba access to update product in the database. But when I debug, it stops at the DoCmd statement and got run-time error. I've made research about this kind of error and code, and had changed the code but still caused an error. Below is my simple code to update the product value.
Sub UpdateProduct()
Dim mySql As String
mySql = "UPDATE " & Forms!UPDATE_PRODUCT!cbxLensType _
& " SET LOT_NO = " & Forms!UPDATE_PRODUCT!txtLotNo _
& " WHERE EAN_CODE = " & Forms!UPDATE_PRODUCT!txtEan & ";"
DoCmd.RunSQL mySql
End Sub
Could you help me to explain what is the problem to my code? Is it because of the update syntax?
Thanks in advance.
**New to access vba
Since EAN_CODE is Text type you need to enclose it inside single quotes.
Sub UpdateProduct()
Dim mySql As String
mySql = "UPDATE [" & Forms!UPDATE_PRODUCT!cbxLensType _
& "] SET LOT_NO = " & Forms!UPDATE_PRODUCT!txtLotNo _
& " WHERE EAN_CODE = '" & Forms!UPDATE_PRODUCT!txtEan & "';"
DoCmd.RunSQL mySql
End Sub
If LOT_NO is also a Text type, make sure that it is also enclosed in Single quotes.

How to use combobox to search for record?

I have a combo box on a form that I use to search for record based on [WorkDate] and it works fine. the problem i have is that the combo box has 3 columns but it only does the lookup based on the first column. The columns in the combobox dropdown are WorkDate | WorkType | Comment
here is the code i have:
`Private Sub ctlSearch_AfterUpdate()
On Error GoTo myError
Dim rst As DAO.Recordset
Set rst = Me.RecordsetClone
rst.FindFirst "[WorkDate] = " & "#" & Format(Me.ctlSearch.Column(0), "yyyy/mm/dd") & "#" And "[WorkType] = '" & Me.ctlSearch.Column(1) & "'"
Me.Bookmark = rst.Bookmark
leave:
Me!ctlSearch = Null
If Not rst Is Nothing Then Set rst = Nothing
Exit Sub
myError:
MsgBox "Record Not Found"
Resume leave
End Sub`
I have narrowed down the issue to this line in the code:
rst.FindFirst "[WorkDate] = " & "#" & Format(Me.ctlSearch.Column(0), "yyyy/mm/dd") & "#" And "[WorkType] = '" & Me.ctlSearch.Column(1) & "'"
Also whenever I replace the above line of code with
rst.FindFirst "[WorkDate] = " & "#" & Format(Me.ctlSearch.Column(0), "yyyy/mm/dd") & "#"
or
rst.FindFirst "[WorkType] = '" & Me.ctlSearch.Column(1) & "'"
it works perfectly but for the life of me I cant get the lookup to work together. I have spent days trying to get this to work. Any help will be much appreciate.
You have a typo in your line. When you tried to combine the statements it looks like you added some extra quotes around the AND part.
rst.FindFirst "[WorkDate] = " & "#" & Format(Me.ctlSearch.Column(0), "yyyy/mm/dd") & "#" And "[WorkType] = '" & Me.ctlSearch.Column(1) & "'"
rst.FindFirst "[WorkDate] = #" & Format(Me.ctlSearch.Column(0), "yyyy/mm/dd") & "# And [WorkType] = '" & Me.ctlSearch.Column(1) & "'"
When writing a query statement in VBA the needs to be a string contained in quotes like so.
rst.FindFirst "Field1 = #01/02/2014#"
If you want to change the date to be a variable of some sort you need to append it to the string like you did above.
rst.FindFirst "Field1 = #" & dateField & "#"
The difference between what I wrote and what you had is that you don't need to divide the string up and put quotes around every part. Quotes only need to surround the parts that aren't variables.

What does "Too few parameters. Expected 1." on MS Access mean?

I'm trying to update records in my form. It's a restaurant reservation system. Given the Table #, the form can let the user input the Customer ID of the person reserving, the reservation time and date. But when I click on the "update" button in my form, a text box will pop up with this:
And whatever I put in it, the runtime error "too few parameters. expected 1." pops up. Sometimes a "Reserved Error" will pop up. Could someone help me? It's the last step before I could finally finish this project.
This is my code for updating the record:
Private Sub Command8_Click()
On Error GoTo errHandling
Dim strSQL As String
strSQL = "UPDATE tblReserve SET CustomerID = " & """" & Me.txtCustID & """" & _
", ResDate = " & """" & Me.txtResDate & """" & ", ResTime = " & """" & Me.txtTime & """" & " WHERE TableNum =" & Me.TableNum
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
CurrentDb.Execute strSQL, dbFailOnError
DoCmd.Close
Exit Sub
errHandling:
MsgBox Err.Description
End Sub
Screenshot of VBA editor with Debug.Print strSQL
As revealed in our [chat][1], the essence of the problem was that [TableNum] is a text field and therefore its value had to be enclosed in quotes:
"... WHERE TableNum = '" & Me.TableNum & "'"
[1]: https://chat.stackoverflow.com/rooms/42746/discussion-between-nutellafella-and-gord-thompson)
Try something like this
strSQL = "UPDATE tblReserve SET CustomerID = " & Me.txtCustID & _
", ResDate = " & "'" & Me.txtResDate & "'" & ", ResTime = " & "'" & Me.txtTime & "'" & " WHERE TableNum =" & Me.TableNum
I am not sure why you have 2 sets of double quotes inside double quotes, I think what you were looking for is single quotes :)
However, there are much better ways to format sql than this. Also this seems like homework, so study up!