I have a Database that I need to use, but it has some errors which I have to fix.
Since I am not an expert in MS-Access, I can not figure out where the mistakes are.
The first error
Run-time. Could not find field '| 1' to which reference is made in the expression.
is thrown when pressing the print button.
Opening the debug, I found this piece of code:
Private Sub Pulsante40_Click()
If Me!Campo51 = False Then
Select Case [schede]![S_Stampa_Ordini].[ordinamento]
Case 1
DoCmd.OpenReport "Stampa Ordini BY DATA", , , " (DATA_AGG Between #" & Format$(Me.[Dal], "mm/dd/yyyy") & "# And #" & Format$(Me.[Al], "mm/dd/yyyy") & " 23:59#) AND Tipo = """ & Me.TipoL & """"
Case 2
DoCmd.OpenReport "Stampa Ordini BY CLIENTE", , , " (DATA_AGG Between #" & Format$(Me.[Dal], "mm/dd/yyyy") & "# And #" & Format$(Me.[Al], "mm/dd/yyyy") & " 23:59#) AND Tipo = """ & Me.TipoL & """"
Case 3
DoCmd.OpenReport "Stampa Ordini BY LAVORAZION", , , " (DATA_AGG Between #" & Format$(Me.[Dal], "mm/dd/yyyy") & "# And #" & Format$(Me.[Al], "mm/dd/yyyy") & " 23:59#) AND Tipo = """ & Me.TipoL & """"
Case 4
DoCmd.OpenReport "Stampa Ordini BY DATA_CONS", , , " (DATA_AGG Between #" & Format$(Me.[Dal], "mm/dd/yyyy") & "# And #" & Format$(Me.[Al], "mm/dd/yyyy") & " 23:59#) AND Tipo = """ & Me.TipoL & """"
End Select
FDipendente = 0
Else
DoCmd.OpenForm "FiltroStampa", , , , , A_DIALOG
End If
End Sub
It gives me error on line:
Select Case [schede]![S_Stampa_Ordini].[ordinamento]
The second error
Compile Error, could not find the method or data member
is thrown when I open the mask minutes and select
Legno, or Lavorazione Ext
code:
Private Sub Tipo_AfterUpdate()
Select Case Me.Tipo
Case "C"
Me.[SSMin-In].scheda.testo0.Caption = "Lavorazione:"
Case "L"
Me.[SSMin-In].scheda.testo0.Caption = "Cod.Prev.:"
Case "E"
Me.[SSMin-In].scheda.testo0.Caption = "Cod.Prev.:"
End Select
End Sub
It gives me the error on line:
Private Sub Tipo_AfterUpdate()
It has been days that I'm trying to solve the Database, or at least to start studying the visual basic to understand something. Unfortunately I only know java and my colleagues can not help me. Thank you in advance for an answer and I apologize if I was unclear or did not provide enough information.
It looks to me like your code is trying to refer to controls on your form, but in an invalid way (I can't quite understand what the code is trying to do because I don't read the language, and I don't know what controls you have on the form).
For example, to get the value of a combo box on a form, you would normally type something like Me.cboMyCombo.Value. To get the value of a field bound to this form, you would type something like Me!MyField or Me![My Field].Value.
Your calls to [schede]![S_Stampa_Ordini].[ordinamento] and Me.[SSMin-In].scheda.testo0.Caption look like they have a few too many methods on the end.
One way to find out what methods are acceptable is to start typing and let the pop-up menus guide you. For example, type Me. and see what pops up. In my example, cboMyCombo would be one of the items in the menu. Choose it, and you will see a new menu with Value as a choice.
You can also use the 'Expression Builder'.
You might want to try to copy your SQL into a query (or two). Make sure they actually produce the results you want. Then, you can call DoCmd.OpenQuery "qappYourNewQueryName". It is easier to read.
INSERT INTO [MIN-OUT]
( LAVORAZION, TIPO, MINUTI )
SELECT DISTINCTROW
[MIN-IN].LAVORAZION,
[MIN-IN].TIPO,
0 FROM [MIN-IN]
GROUP BY
[MIN-IN].LAVORAZION,
[MIN-IN].TIPO;
' What is this?
, ID_Dipendente )
SELECT DISTINCTROW
[MIN-IN].LAVORAZION,
[MIN-IN].TIPO,
[Forms]![Minuti].[dipendente] AS Espr1
FROM [MIN-IN]
GROUP BY
[MIN-IN].LAVORAZION,
[MIN-IN].TIPO,
[Forms]![Minuti].[dipendente];")
Related
I am dealing with some legacy tech at my new job. Everything is either VBS or VBA and SQL Server 2005 is still running for at least 1 server, and 2008 on another. I can't change the tech I have to work with, so please don't respond with "Just use PowerShell" ... which is all I got from the Microsoft forums.
I need to modify an existing VBScript to iterate through the records of a table and give each page of a document a page number. The page number starts at 1 and resets to 1 every time the location folder changes, as defined by the row's value in the column Path. So I need to compare the current row's Path to the previous row's Path to see if there is a change.
From the specs request:
Use the following structure:
Outermost folder = Box field
Sub-folder = File Folder field
Docs within will each begin at "0000001"
Sub-folder = File Folder field
Docs within will each begin at "0000001"
Sub-folder = File Folder field
Docs within will each begin at "0000001"
Here is a very simple but effective Excel script that works, unfortunately I have to use VBScript so a third-party software can run the script:
=IF "Folder field in this row" = "Folder field in row above"
True = "above column" (beg doc of previous doc) + "pgcount of previous doc"
False = "1"
Here is the existing SQL statement from within the VBScript (Sorry for the naming convention - it is not my choice):
UPDATE tblpage
SET tblpage.UID = newtable.keyid
FROM tblpage inner join (SELECT PKEY, '" & prefix & "' + REPLICATE(0, " & padnum & " -
LEN(convert(varchar(" & padnum & "),(" & startnum & " + rank() OVER (ORDER
BY TBLDOC." & sortfield & ") + Page - 2)))) + CONVERT(nvarchar(" & padnum &
"), convert(varchar(" & padnum & "),(" & startnum & " + rank()
OVER (ORDER BY TBLDOC." & sortfield & ") + Page - 2))) AS keyid
FROM tblpage
inner join tbldoc on tblpage.id = tbldoc.id) as newtable ON newtable.pkey = tblpage.pkey;
variables taken from user input in VBScript - explanation
prefix - optional text prefix to the iterative number ie "SET" for "SET0000001"
padnum - number of 0s before iteration begins ie "000000" for "SET0000001"
startnum - starting number for the iteration ie "1" in "SET0000001"
sortfield - which table column to sort by ie a table's UID.
The above SQL does the iteration correctly but doesn't reset on new folder. I have been looking into SQL SERVER – How to Access the Previous Row and Next Row value in SELECT statement? – Part 2, but I am still quite confused.
My thoughts are that I join just the Path to the newtable based on the row's UID - 1, and then a case statement to compare them. If different, reset the page number. If the same, continue as normal.
Thanks!!
This answer comes from my old CS college roommate, but he doesn't have a Stack account(!?) so I'll post for him...
Even though the online docs for the OVER function are stamped 2008+, it actually does work just fine in 2005, as evidenced by the original posted query. This also means I can bypass all the nastiness of comparing previous row to current row by using PARTITION BY to reset on the chosen column Path
UPDATE tblpage
SET tblpage.UID = newtable.keyid
FROM tblpage inner join (SELECT PKEY, '" & prefix & "' + REPLICATE(0, " & padnum & " -
LEN(convert(varchar(" & padnum & "),(" & startnum & " + rank() OVER (
PARTITION BY TBLDOC.Path ORDER
BY TBLDOC." & sortfield & ") + Page - 2)))) + CONVERT(nvarchar(" & padnum &
"), convert(varchar(" & padnum & "),(" & startnum & " + rank()
OVER (PARTITION BY TBLDOC.Path ORDER BY TBLDOC." & sortfield & ") + Page - 2))) AS keyid
FROM tblpage
inner join tbldoc on tblpage.id = tbldoc.id) as newtable ON newtable.pkey = tblpage.pkey;
I have multiple comboboxes where users have the option of selecting an item. If no item is selected I insert NULL into SQL-SERVER:
if cboSchool.text="" then
g_strSQL = g_strSQL & "NULL,"
else
g_strSQL = g_strSQL & "'" & cboschool.itemdata(cboschool.listindex) & "',"
End if
My problem is as follow: Later on I allow the user to edit the information that they previously didn't select. So later on when they want to edit the information, I need to be able to have the application realize that there was a value or there wasn't a value in the table in (SQLSERVER), compare if its different from the value that was selected. And if the information is different then need to update the table. This is what my code looks for EDIT:
If g_RS!SchoolID <>cboSchool.ItemData(cboSchool.ListIndex)Then
g_strSQL2 = g_strSQL2 & " School ID = '" & cboSchool.ItemData (cboSchool.ListIndex) & "',"
End If
The problem Im seeing is that g_RS!SCHOOLID shows as "NULL", however it does notice that the value is different from cboschool.itemdata and it just skips to the end of the if statement. I don't understand how it doesn't see the difference.
If Val("" & g_RS!SchoolID) <> cboSchool.ItemData(cboSchool.ListIndex) Then
It's because of the null value that it doesn't see a difference.
You could have:
If g_RS!SchoolID <> "Hello world!" Then
g_strSQL2 = "DROP TABLE X"
Else
MsgBox ("g_RS!SchoolID = Hello world!")
End If
and as long as SchoolID is NULL you'd get a messagebox.
You could fix this with something like:
If Iif(IsNull(g_RS!SchoolID), "", g_RS!SchoolID) <> cboSchool.ItemData(cboSchool.ListIndex) Then
'do stuff
End If
I have an SqlDataReader that is declared like this:
Dim myReader As SqlDataReader
myReader = SqlHelper.ExecuteReader(ConnectionString, "storedProcedure1", CInt(myTextBox.Text))
Later I use the results like this:
If myReader.HasRows Then
While myReader.Read()
Row = Table1.NewRow()
Row.Item("REF") = myReader.GetString(0)
Row.Item("CD") = myReader.GetString(1)
Row.Item("NAME") = myReader.GetString(2)
Row.Item("KEY") = myReader.GetDecimal(3)
Row.Item("STRING") = myReader.GetString(0) & " - " & myReader.GetString(1) & " - " & myReader.GetString(2).ToString().Replace("'", "") & " - " & myReader.GetString(4).ToString().Replace("'", "")
Table1.Rows.Add(Row)
'Fill Drop Down
drpMenu.Items.Add(New ListItem(myReader.GetString(0) & " - " & myReader.GetString(1) & " - " & myReader.GetString(2).ToString().Replace("'", "") & " - " & myReader.GetString(4).ToString().Replace("'", "")))
End While
End If
myTextBox is a textbox that the user enters a possible location number that gets searched for using the stored procedure. If the user enters a valid location number, this works great and I have no problems. If they enter a non-existent location number, I get an exception:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
I would think that the If myReader.HasRows line would keep me from trying to read and manipulate results that don't exist but there must be something I'm missing. myTextBox is already being validated elsewhere in the code to make sure the user typed in an integer without any wacky characters so bad input doesn't seem to be the problem either.
How do I find out whether the location number exists before calling SqlHelper.ExecuteReader()? Or maybe the better question is how do I gracefully handle this exception and tell the user the location wasn't found?
EDIT: Here's the stored procedure.
ALTER PROCEDURE [dbo].[storedProcedure]
-- Add the parameters for the stored procedure here
#MBR as integer
AS
BEGIN
EXEC ('{CALL RM#IMLIB.spGETLOC( ?)}', #MBR) at AS400
END
EDIT #2: When I run the stored procedure in SMS and pass a valid location, it returns what I expect. If I pass an invalid location number, it returns nothing.
First. create a local variable...and cast the textbox value to the local variable...to make sure that isn't the error.
dim myValue as Int32
myValue = '' convert textbox value to an int.
Second...typically, my datareader code looks like this.
If (Not ( reader Is Nothing) ) then
If reader.HasRows Then
Do While reader.Read()
Console.WriteLine(reader.GetInt32(0) _
& vbTab & reader.GetString(1))
Loop
End If
End If
(You'll have to adjust the GetInt32 or GetString and the ordinal number to your specific case of course).
My guess is that your child-procedure (RM#IMLIB.spGETLOC) has logic in it that does NOT return a row if there isn't a match.
You can still return a result....that has no rows in it. ** (Read that again).
For example
Select ColA, ColB from dbo.MyTable where 0=1
This will return a result, with no rows. That is different from not returning a(ny) select statement..(Read that again)
My guess is that this little nuance is where you get an issue.
APPEND:
If you cannot change the child-stored procedure....
Create a #TempTable...
Populate the #TempTable with the child-stored procedure.
Do a select from the #TempTable.
Here is a generic example:
IF OBJECT_ID('tempdb..#TempOrders') IS NOT NULL
begin
drop table #TempOrders
end
CREATE TABLE #TempOrders
(
ColumnA int
, [ColumnB] nchar(5)
)
/* Note, your #temp table must have the exact same columns as returned by the child procedure */
INSERT INTO #TempOrders ( ColumnA, ColumnB )
exec dbo.uspChildProcedure ParameterOne
Select ColumnA, ColumnB from #TempOrders
IF OBJECT_ID('tempdb..#TempOrderDetails') IS NOT NULL
begin
drop table #TempOrderDetails
end
I finally figured out my issue.
Later in my code, I had a DataRow array that was empty if the location couldn't be found. I was getting the exception because it was trying to grab an Item from array(0) which makes complete sense.
I missed it initially because I thought it was a DataRow, not a DataRow array. Man, I hate fixing up code I didn't write...
I'm trying to amalgamate a few address feilds into one text box on a report:
=[City]+", "+[County]+", "+[Post Code]
However not all records have an entry in the [County] column, which means that nothing shows in the textbox at all for these records. So I tried an Iif statement:
=IIf([County],[City]+", "+[County]+", "+[Post Code],[City]+", "+[Post Code])
This didn't work, how can I make the text box show whatever fields are present?
Easiest solution IMO: Use Nz.
=[City]+", "+Nz([County]+", ")+[Post Code]
Though you may want ot use & instead of +. In Access + means summation, but & means concatenation.
You were so close!
=[City]+", "+[County]+", "+[Post Code]
should be:
=[City]&", "&[County]&", "&[Post Code]
Remember, a NULL trumps everything in math, so using the plus operator was giving you a NULL result every time any field was blank.
you were close with your IIf statement.
You are missing one of 2 possible tests
if only nulls can appear,
=IIf(IsNull([County]),[City]+", "+[County]+", "+[Post Code],[City]+", "+[Post Code])
if it can be empty ("") or null
=IIf(len(""&[County]),[City]+", "+[County]+", "+[Post Code],[City]+", "+[Post Code])
You can take advantage of the fact that the two concatenation operators (+ and &) handle Nulls differently.
? "A" + Null
Null
? "A" & Null
A
So you could do this ...
? "A" & ", " & "B" & ", " & "C"
A, B, C
? "A" & ", " & Null & ", " & "C"
A, , C
... but if you don't want two commas when you have Null instead of the second string value, do this instead:
? "A" & (", " + Null) & ", " & "C"
A, C
If that all makes sense, apply the same pattern to your text box control source:
=[City] & (", " + [County]) & ", " & [Post Code]
You don't need functions (IIf, IsNull, Len, and/or Nz) to get what you want here.
Try this please: Rather super ugly thought... When Chr(13) and Chr(10) are there it will never be empty.
IIf(Isnull([County]),
IIf(Isnull([Post Code]),
IIf(IsNull[Post Code]), "No Address", [Post Code]),
[City] + Chr(13) & Chr(10) +[Post Code]),
[Country] + Chr(13) & Chr(10) + [City] + Chr(13) & Chr(10) +[Post Code])
I have the following ASP code below which is used within a import from a .csv file. I am getting the error on line
rs_add_pg_asset_attr("level_3_integer_attribute_description") = rs_get_costs("sp_import_pg_attribute_value")
I'm guessing the code is trying to set 2 columns in two different recordsets to be equal to the same thing? Correct me if I'm wrong. The data in level_3_integer_attribute_description is type decimal(13,3), NULL and the data in sp_import_pg_attribute_value is a whole range of different values type varchar(255), NULL.
I cannot work out why this is failing.
str_get_pg_attribute_id_sql = "SELECT * FROM tbl_level_3_cbs_attribute WHERE level_3_cbs_attribute_description = '" & rs_get_costs("sp_import_pg_attribute") & "'"
str_get_pg_attribute_id_sql = str_get_pg_attribute_id_sql & " AND level_3_cbs_id = " & int_level_3_id
rs_get_pg_attribute_id.Open str_get_pg_attribute_id_sql, dbConnection, 3
if rs_get_pg_attribute_id.RecordCount <> 0 then
''//Does the attribute already exist?
str_get_pg_attribute_sql = "SELECT * FROM tbl_asset_level_3_attribute_link WHERE "
str_get_pg_attribute_sql = str_get_pg_attribute_sql & "level_3_cbs_attribute_id = " & rs_get_pg_attribute_id("level_3_cbs_attribute_id") & " AND asset_level_3_id = " & int_pg_asset_id
rs_get_pg_attribute.Open str_get_pg_attribute_sql, dbConnection, 3
if rs_get_pg_attribute.RecordCount = 0 then
''//No, add the attribute record
sqlString="select top 1 * from tbl_asset_level_3_attribute_link"
rs_add_pg_asset_attr.Open sqlString, dbConnection, adOpenKeyset, adLockOptimistic
rs_add_pg_asset_attr.AddNew
rs_add_pg_asset_attr("level_3_cbs_attribute_id") = rs_get_pg_attribute_id("level_3_cbs_attribute_id")
rs_add_pg_asset_attr("asset_level_3_id") = int_pg_asset_id
if rs_get_pg_attribute_id("level_3_cbs_attribute_type") = "I" then
rs_add_pg_asset_attr("level_3_integer_attribute_description") = rs_get_costs("sp_import_pg_attribute_value")
else
rs_add_pg_asset_attr("level_3_string_attribute_description") = rs_get_costs("sp_import_pg_attribute_value")
end if
Are you sure that level_3_integer_attribute_description is an existing field name, no typo error anywhere ?
If so, is the data you want to put into this decimal value, a correct string representation of a floating value ? No problems with decimal points and comma's ?
Since the error is a Type Mismatch error, you probably have a type mismatch error :)
Try this:
rs_add_pg_asset_attr("level_3_integer_attribute_description") = _
tryCDbl( rs_get_costs("sp_import_pg_attribute_value"))
and then:
function tryCDbl( something )
dim retval
retval = 0 ''// fallback
on error resume next
if isNumeric( something ) then
retval = cdbl( something)
end if
tryCDbl = retval
end function
We found the answer to this question. The problem was the Import was trying to assign a blank space into a decimal column. Thanks for your help. I'm stuck on something else now!