My database has a job number field that consists of year+month/serialnumber+type. There can be multiple jobs with the same job number:
201812/6Door
201812/6Stair
201812/6Wardrobe
When the user wants to change the date of any/all of these records I want all 201812/6 jobs to show in a form.
I have successfully used the OnlyDigits function below to pull only numbers from the text field: OnlyDigits(JobNumber) = 2018126. But I can't figure out how to filter the form to show all jobs containing 2018126.
I have tried using this query but get an error saying expression typed incorrectly or is too complex.
SELECT onlydigits(jobnumber) AS JobNumberDigits, tbldelivery.DelDateDoors, tbldelivery.Lag, tbldelivery.ProductionDate, tbldelivery.OrderNumber, tbldelivery.JobNumber
FROM tbldelivery
WHERE (((onlydigits(jobnumber))=OnlyDigits([Forms]![tblDelivery]![JobNumber])));
I also tried using a where expression in Docmd.OpenForm but that didn't work either. Can anyone suggest how I use this function to filter?
Public Function OnlyDigits(ByVal pInput As String) As String
Static objRegExp As Object
If objRegExp Is Nothing Then
Set objRegExp = CreateObject("VBScript.RegExp")
With objRegExp
.Global = True
.Pattern = "[^\d]"
End With
End If
OnlyDigits = objRegExp.Replace(pInput, vbNullString)
End Function
Try specifying the parameter to free Access from guessing:
PARAMETERS
[Forms]![tblDelivery]![JobNumber] Text;
SELECT
OnlyDigits(JobNumber) AS JobNumberDigits,
tbldelivery.DelDateDoors,
tbldelivery.Lag,
tbldelivery.ProductionDate,
tbldelivery.OrderNumber,
tbldelivery.JobNumber
FROM
tbldelivery
WHERE
OnlyDigits(JobNumber)=OnlyDigits([Forms]![tblDelivery]![JobNumber]);
or:
WHERE
OnlyDigits(CStr(Nz(JobNumber, 0)))=OnlyDigits([Forms]![tblDelivery]![JobNumber]);
Related
I need to get the ID parameter in a URL, for example I have
http://apps/inventory/others.aspx?ID=8678
How do I extract the 8678, I've looked at the method of the Object WinHttp.WinHttpRequest.5.1 but I haven't found anything. Could that be possible with a simple substring? The URL is always the same and there is always one GET parameter,
Thanks
Try like this:
Option Explicit
Public Sub TestMe()
Debug.Print ExtractAfter("http://apps/inventory/others.aspx?ID=8678", "ID=")
Debug.Print ExtractAfter("http://apps/inventory/others.aspx?ID=867843", "ID=")
End Sub
Public Function ExtractAfter(strInput As String, strAfter As String) As String
ExtractAfter = Mid(strInput, InStr(strInput, strAfter) + Len(strAfter))
End Function
This is what you get in the immediate window:
8678
867843
In VBA, assuming you have the url in a variable url:
Debug.Print Mid(url, InStr(url, "ID=") + 3)
However, works only correct if the ID parameter is always present and always the only paramter, else you need some more sophisticated string handling.
How can I write NOT IN in TextBox expression?
I must check if some field value not belong to some list of strings, and then do some work.
Example:
Iif(SomeField.Value NOT IN ('Text1', 'Text2'), DoSomething, nothing)
I wrote code like this and got error when previewing report, and error was :
Overload resolution failed because no accessible 'Iif' accepts this number of type arguments
How can I do this stuff?
Try this small piece of custom code that accepts a string array. Just paste it into the report code section of the report..
Public Shared Function ValueExists(ByVal arr() as string, checkVal as string)
Dim i As Long
For i = LBound(arr) To UBound(arr)
If arr(i) = checkVal Then
return true
Exit Function
End If
Next i
return false
End Function
Usage would involve splitting the string into an array using the Split function
like so:
=iif(Code.ValueExists(Split("Your,comma,separated,string,in,here",","),"StringYouWantToFind")
,"Your value exists"
,"your value does not exist")
You can simply write the code like this:
Iif(SomeField.Value <> 'Text1' AND Field.Value <> 'Text2' , DoSomething, nothing)
I got this one in one report:
=iif(join(Parameters!Parameter1.Value,",") like "*" & Fields!Field1.Value & "*","Color1","Color2")
This instruction helps me to determine the fill colour of a cell inside a tablix, where:
Parameter1 is a multivalue parameter.
"Join" lets me have a string with all selected values from a multivalue parameter, eg. "value1,value2,value3,value4"
Field1 is the field that contains the values filtered by Parameter1
Color1 is the color if the value of the cell is included in the selection of parameter
else Color2
works well
After applying the unpivot procedure, I have an Amount column that has blanks and other characters ( like "-"). I would like to convert those non-numberic values to zero. I use replace procedure but it only converts one at the time.
Also, I tried to use the following script
/**
Public Overrides Sub Input()_ProcessInputRows(ByVal Row As Input()Buffer)
If Row.ColumnName_IsNull = False Or Row.ColumnName = "" Then
Dim pattern As String = String.Empty
Dim r As Regex = Nothing
pattern = "[^0-9]"
r = New Regex(pattern, RegexOptions.Compiled)
Row.ColumnName = Regex.Replace(Row.ColumnName, pattern, "")
End If
End Sub
**/
but i'm getting error.I don't much about script so maybe I placed in the wrong place. The bottom line is that I need to convert those non-numberic values.
Thank you in advance for your help.
I generally look at regular expressions as a great way to introduce another problem into an existing one.
What I did to simulate your problem was to write a select statement that added 5 rows. 2 with valid numbers, the rest were an empty string, string with spaces and one with a hyphen.
I then wired it up to a Script Component and set the column as read/write
The script I used is as follows. I verified there was a value there and if so, I attempted to convert the value to an integer. If that failed, then I assigned it zero. VB is not my strong suit so if this could have been done more elegantly, please edit my script.
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
' Ensure we have data to work with
If Not Row.ColumnName_IsNull Then
' Test whether it's a number or not
' TryCast doesn't work with value types so I'm going the lazy route
Try
' Cast to an integer and then back to string because
' my vb is weak
Row.ColumnName = CStr(CType(Row.ColumnName, Integer))
Catch ex As Exception
Row.ColumnName = 0
End Try
End If
End Sub
I have a function that I want to return different Listboxes based on a string argument.
Here is the function:
Here is the function:
Private Function returnList(name As String) As AccessObject
If name = "app" Then
returnList = Me.Controls("List61")
'I have also tried the following:
'returnList = Me.List61, returnList = Forms![Daily Reports]![List61]
ElseIf name = "lpar" Then
'..several more cases
End If
End Function
Whenever I try to call it, I get a "Run-time error '91': Object variable or With block variable not set." And when I use the debugger, it tells me that the reference to list61(Me.list61, Me.Controls("List61")) is null.
Anyone have any idea how to fix this? Any help would me much appreciated.
The most important thing to note is; as you are now handling "Objects" instead of "variables" you have to put the word "Set" in front of the object variable. Also change the AccessObject type to ListBox.
Private Function returnList(name As String) As ListBox
If name = "app" Then
Set returnList = Me.Controls("List61")
'I have also tried the following:
'returnList = Me.List61, returnList = Forms![Daily Reports]![List61]
ElseIf name = "lpar" Then
'..several more cases
End If
End Function
I've been looking everywhere for a way of accessing a table's description (same one that appears when you right click a table>table properties) through a SELECT query.
I tried using MSysObjects but I can only retrieve the name of the table using that.
Is it possible to do this through a query or is VBA needed?
As Remou says, you can't get it from a query (but you can include a function that returns it in a query). Here's another function:
Public Function GetTableDescr(stTableName As String) As String
On Error Resume Next
GetTableDescr = CurrentDb.TableDefs(stTableName).Properties("Description").Value
End Function
Here's a query that returns all the non-system tables, with their dates and descriptions (using the function above):
SELECT MSysObjects.Name, msysobjects.datecreate, msysobjects.dateupdate, GetTableDescr([Name]) AS Description
FROM MSysObjects
WHERE (((MSysObjects.Name) Not Like "~*") AND((MSysObjects.Name) Not Like "MSys*") and ((MSysObjects.Type)=1));
Finally, you can do an almost identical function for queries. The trick I found is that you only return non-inherited descriptions, otherwise if a query has no description you get the description of the queried object:
Public Function GetQueryDescr(stQryName As String) As String
On Error Resume Next
If CurrentDb.QueryDefs(stQryName).Properties("Description").Inherited = False Then
GetQueryDescr = CurrentDb.QueryDefs(stQryName).Properties("Description").Value
End If
End Function
The On Error Resume Next is necessary, because until the object has a description the property is null.
You can get the description from the table schema or from TableDef properties, but I do not think a standard query will work.
Set rs = CurrentProject.Connection.OpenSchema(adSchemaTables, _
Array(Empty, Empty, "Rules", Empty))
Debug.Print rs!Description
Using GetQueryDescr() above, you can run this query against the hidden sys table
SELECT MSysObjects.Name, GetQueryDescr([Name]) AS Properties, MSysObjects.DateCreate, MSysObjects.DateUpdate
FROM MSysObjects
WHERE (((MSysObjects.Name) Not Like "~sq_*") AND ((MSysObjects.Type)=5));
type 5 is for queries