Orderby Syntax

Nov 2, 2004

I want to basically perform a "Sort by ascending" Function.

I presume I have to grab the focus of the Item I want to order by.

So :

me.(Field).Setfocus

But then what is the code for running the Sort by ascending/Descending?


My data is currently in a list of text boxes. When I normally 'Sort by ascending' the function works fine.. so I just need to activate that....

View Replies


ADVERTISEMENT

Orderby

Apr 26, 2006

Hallo everyone,

I have a table with one of its column value as "B" or "D" or "E".

Now i am in need to display the rows using the select statement with the following conditions.

1. First display the rows with value "D"
2. then display the rows with value "E"
3. then display the rows with value "B"

Is it possible to specify the above condition in a orderby clause.

thanks,

aravind.s

View 1 Replies View Related

OrderBy With Wildcards

Oct 13, 2006

I am trying to get the OrderBy to recognize wildcards (or to that effect). A scenario would be I would have more than one name in a field, EX: Name2, 4, 6. How do I use wildcards in the OrderBy and they are recognized.

ORDER BY (Table.Field)="Name1", (Table.Field)="Name2", (Table.Field)="Name3", (Table.Field)="Name4", (Table.Field)="Name5", (Table.Field)="Name6", (Table.Field)="Name7", (Table.Field)="Name8";

View 2 Replies View Related

Listbox OrderBy

Jun 20, 2006

Hi,
I have a list box based on a quite a complex query. I would like give the user the option to dynamically sort the list box.

How can I refer to my listbox's SQL rowsource and add a sort order using VB?
i.e.
Private Sub CmdButtonSortByName_Click
Dim strSQL as String
strSQL = me.listbox.rowsource & "ORDER BY FieldName;"
me.listbox.rowsource = strSQL

I am aware of how I could do this if my SQL was in VB i.e.:

Dim strSQL as String
Dim strSortOrder as String
Dim optSort as Integer

Select Case optSort.Value
Case 1
strSortOrder = "ORDER BY LastName;"
Case 2
strSortOrder = "ORDER BY FirstName;"
End Select

strSQL = "SELECT FirstName, LastName FROM TblName " & strSortOrder
Me.ListBox.Rowsource = strSQL


....but my query is far more complex than this and I dont want to have to keep calling the code each time I need to requery my form.

Thanks
BF

View 14 Replies View Related

OrderBy Problem

Apr 15, 2005

In my db I have a report that I would like to sort by different fields. I tried coding this using option buttons, a command button, and the "Case" statement. While putting in the OrderBy portion of the code I keep getting errors in relation to the syntax. I'm not sure how long I worked with it and got absolutely nowhere. Can someone clue me in please? Here's my code:

Private Sub Command14_Click()
Select Case Me!Frame5.Value
Case 1
'Sort by Military Occupational Specialty (MOS) ascending
DoCmd.OpenReport ("Report1")
OrderBy MOS

Case 2
'Sort by Military Occupational Specialty (MOS) descending
DoCmd.OpenReport ("Report1")
OrderBy MOS, DESC

Case Else
MsgBox ("Please select an option before attempting to open the report.")

End Select
End Sub

View 6 Replies View Related

Weird OrderBy Problem

Feb 21, 2006

Hi all,
Found a weird problem when editing records in continuous form view (and datasheet view) when a particular memo field is being used by OrderBy to sort the data. When i have just created a new record and tab to the next record, the record i was just in jumps to the top of the records, but in its place is an exact copy of the record above. Very confusing, and looks like a redraw bug but it happens on all PCs.

What happens is ... (letters relate to records going down the screen)

A
B
C
D ....new record being entered then <TAB> and ...

D ....has jumped up here
A
B
C
C ....duplicate of C - but duplicate record never created in the table
E ....new record

When i quit the form and come back in, everything is ok

As far as i know, OrderBy only takes effect if you refresh the form (which i'm not doing). It works fine if i take off OrderBy, or if i use another field with OrderBy. So is there some problem using OrderBy with a memo field, and how is this making my records jump about?

help!

Pete

View 1 Replies View Related

Using OrderBy Gives Error At Reopening Form.

Nov 15, 2006

I have a form where the recordsource is a stored procedure.

This forms shows a list. When the user clicks on a column title, the column is sorted by using OrderBy in VBA:

f.i.:

Private Sub lblCode_Click()

Me.OrderBy = "strCode"

End Sub

As a result, in the properties of the form, for the property Order By, the fieldname is filled in (f.i. strCode).

This works fine, but when the form is closed, access saves the property Order By.

Next time the form is opened, it gives an error: The recordsource <storedprocedurename> specified on this form does not exist.

When I remove the fieldname in the Order By property of the form, the form opens without an error.

I have tried to clear the Order By property by using Me.OrderBy = "" in the Close event of the form, but this does not work.

Any solution ?

View 2 Replies View Related

Modules & VBA :: OrderBy When Opening A Form

Nov 29, 2013

I'm trying to have a form sorted in a particular order when it's opened.

When using the "order by" option in the properties sheet, it is sorted the way I want the first time I open the form.

However, if I change the order afterwards while using the form (for instance, by right clicking and selecting another sort order), well the next time the form is opened, it is sorted with this new sort order, and not the default one.

So I tried to add the following code :

Code:
Private Sub Form_Open()
Me.OrderBy "employee_name ASC"
Me.OrderByOn = True
End Sub

Which failed epically.

View 6 Replies View Related

Transfering RecordSource/OrderBy Of Form To Report

Oct 17, 2006

I have a subform within a form that displays filtered data based on dynamic selection criteria which is assigned to the RecordSource/OrderBy of the subform. On this form, I have a "Print Results" button -- OnClick, I would like the RecordSource/OrderBy of the subform to be copied to the Report, then run the report. What I have that doesn't work is:

Reports!rpt_frmTaskMain.RecordSource = Forms!frmTaskMain.frmTaskSub1.RecordSource
Reports!rpt_frmTaskMain.OrderBy = Forms!frmTaskMain.frm.TaskSub1.OrderBy

On execution I get error: "Object doesn't support this property or method"

I am thinking this can be done, and likely have the references wrong. Help?

View 1 Replies View Related

Forms :: Can't Clear Filter Or Orderby Permanently On Form

May 14, 2013

I have a tabular form that is based on a select statement (Query) in the source property. It filters & sorts from this select statement. permanently

I have just added a
Me.Filter = "[Form1].[InDate] = #" & MyValue & "# "
Me.OrderBy = "Indate DESC"

This all works fine, filters & sorts on the existing results.However this new filter & sort seems to remain no matter what I do.I have used every variation one me.filter ="" with Me.FilterOn = True, False & every combination.

Me.Filter="" & Me.FilterOn = False does initially seem to clear the lsit to show all records but as soon as type anything that filters the Form on the original, existing underlying select statement the extra Filter Property & Sort properties are occupied with the last filter/sort.

I have manually deleted any remaining Filter Or Sort properties direct from design view, saved, compacted & saved again.Once I use the new me.filter it will always returned as soon an any filter on the form is applied.I definately am not setting it again anywhere. Is there something better than me.filter ="", seen clearallfilters mentioned but not sure if this would apply just to the current form but reluctant to use a blanket clear as I do have quite a lot of other things going on.

Not sure when but many months (If not years) ago my form source stopped being a query and started using the query (sql) direct from the source property.I have left it this way as not sure if any consequence of moving back but don't remember how or how it happened. What are the pros cons of using a separate query.

View 4 Replies View Related

Modules & VBA :: Form Filter And OrderBy Pass To Report

Aug 16, 2014

I am able to filter a data on a continuous form using drop downs and then the following code attached to a cmdbutton to create a report of the filtered data.

Code:
Private Sub Command30_Click()
Dim strWhere As String
If Me.Dirty Then Me.Dirty = False
If Me.FilterOn Then strWhere = Me.Filter
DoCmd.OpenReport "rptconveyorerrors", acViewReport, , strWhere
End Sub

On the same form where I filter the data i can sort it by clicking the headings aswell, however when i generate the report using the above VBA it doesn't take the sort with it and just generates it without the sort.

I am using the following VBA to sort my form

Code:
Me.OrderByOn = True
If Me.OrderBy = "[empname] DESC" Then
Me.OrderBy = "[empname] ASC"
Else
Me.OrderBy = "[empname] DESC"
End If
Me.Refresh

I thought it may be possible to use the following sort of VBA to pass the sort however i cant get it to work:

Code:
Private Sub Command30_Click()
Dim strOrder As String
Dim strWhere As String
If Me.Dirty Then Me.Dirty = False
If Me.FilterOn Then strWhere = Me.Filter
If Me.OrderByOn Then strOrder=Me.OrderByOn

View 1 Replies View Related

Need Help With Syntax Please

Jun 28, 2005

Hi,
in the following code:

Dim dbtmp As DAO.Database
Dim tblObj As DAO.TableDef
Dim rs As DAO.Recordset
Set dbtmp = OpenDatabase("C:WINDOWSBureaudevcli.xls", False, True, "Excel 8.0;")
DoEvents
Set rs = dbtmp.OpenRecordset("select * from [DEVCLI$A1:C10]")

in the last line i would like replace DEVCLI (the Excel sheet name) by a variable to make my program works with any excel file.
What is the syntaxe for that ?
Thanks in advance for help.
VINCENT

View 2 Replies View Related

IIf Syntax

Nov 1, 2005

Think my syntax is wrong here, but not sure where. I would appreciate any help! Thanks!
SELECT a.[FA Ctr], a.[SAP Co], a.[SAP Ctr], a.[GL Co],



IIf([Len([SAP CO])] ="3",""0"' & [a].[SAP CO]", IIf([Len([SAP CO])]="2",""'00"' & [a].[SAP CO]"), IIf([Len([SAP CO])]="1",""'00"' & [a].[SAP CO]", "[A].[SAP CO]"))) AS Expr3
INTO [Interim Table]
FROM Asset_Map AS a

View 11 Replies View Related

IIF Syntax

Mar 12, 2008

Hi there

I'm trying to write a query using an IIF statement in the "Field" property of the Access Query Design Grid the new Column is called F:

there are 3 Columns, System, Etot, Itot in a mytable

Basically in English the query goes,

IF mytable.[System] = 700,
mytable.[Etot] = 0,
mytable.[Itot] = 0
then the newly created derived column
mytable.[F] "N/A"
OTHERWISE
mytable.[F] "OK"

I hope someone understands,

Batwings

View 6 Replies View Related

Syntax For LIKE

Dec 6, 2004

Hi,
I wud like to know why this syntax is not working.
select * from table_name where col_val like 'a%'

This returns the column values that start with 'a'. I was getting the result properly few days ago. But now suddenly this query doesnot give the result. When i tried this out in a website it was working there, but not in access.

Can anybody see what is wrong in this syntax? If the syntax is right where wud be the fault?

View 6 Replies View Related

Need Help With Syntax

Dec 20, 2004

Can someone tell me how to insert the contents of a variable into a table?
I am trying to add selected items from a listbox (Members) into a temporary table (tempMembers). The code is below. On debugging, it picks up the contents of the variable (iMemberID) OK, but adds "0" to the temp table (both are integers). I'm pretty sure the problem is in the Insert statement below (stSQL3), but I can't figure out how to write it!

Any help would be greatly appreciated!
Thanks

stSQL3 = "INSERT INTO tempMembers (MemberID) VALUES & iMemberID & ;"
For Each varItm In Me!Members.ItemsSelected
iMemberID = ctl.ItemData(varItm)
DoCmd.RunSQL stSQL3
Next varItm

View 6 Replies View Related

Syntax

Sep 29, 2005

Can anyone tell me the proper syntax for:

1. Calling another Form from within a Form

2. Calling a module from within a Form

Thanks in Advance

View 5 Replies View Related

Help With Syntax

Sep 4, 2006

Can someone help me on the syntax for the following?
I have two tables: one is TapeNumber and has one field (Tape_No) autonumbered PK. The other table has information about the video and uses the Tape_No as a secondary key.

I have a form to add information about videos. I have the form bound to the first table, so it adds a new TapeNumber when I add a record. I have a subform displaying the video information for that tape (there may be several videos recorded on one tape).

When I add a new tape (or video to an existing tape), how do I save the tape number to the second table?

Thanks!

View 1 Replies View Related

Vba Syntax????????help

Mar 1, 2007

have this code which keeps on giving me this error...I dont know whats wrong with the code please help tried removing the quotes (rstStudents.Open "SELECT * FROM Students WHERE Regno = " & _
txtReg , _
CurrentProject.Connection, _
adOpenStatic, adLockReadOnly, adCmdText) but then it wont retain any records even if they exist in the table

here is the original code

rstStudents.Open "SELECT * FROM Students WHERE Regno = '" & _
txtReg & "'", _
CurrentProject.Connection, _
adOpenStatic, adLockReadOnly, adCmdText




ERROR MESSAGE>>>>>>> Runtime Error '-2147217913 (80040e07)
Data type mismatch in criteria expression


the code is supposed to use number input by user to search in a table and fill all the other fields in the form with the table data (it is run on lost focus of the text box were value has been input)



the whole code :::::




Private Sub txtReg_LostFocus()
Dim rstStudents As ADODB.Recordset
Dim blnFound As Boolean
Dim fldItem As ADODB.Field

blnFound = False

If Me.txtReg = "" Then Exit Sub

Set rstStudents = New ADODB.Recordset
rstStudents.Open "SELECT * FROM Students WHERE Regno = '" & _
txtReg & "'", _
CurrentProject.Connection, _
adOpenStatic, adLockReadOnly, adCmdText

With rstStudents
While Not .EOF
For Each fldItem In .Fields
If fldItem.Name = "Regno" Then
If fldItem.Value = txtReg Then
Me.txtName = .Fields("Name")
Me.txtAdd = .Fields("Address")
Me.txttel = .Fields("Telno")
Me.txtTutor = .Fields("TutorName")
Me.txtbks = .Fields("NoBooksonloan")
blnFound = True
End If
End If
Next

.MoveNext
Wend
End With

If blnFound = False Then

MsgBox "No student record to display"
' ... and reset the form
' cmdReset_Click
End If

rstStudents.Close
Set rstStudents = Nothing

End Sub

View 2 Replies View Related

Syntax

Sep 5, 2007

I am trying to open a PDF from Access. I get it to work but it requires me to hard code the path and fiel name....

The path will always be the same although the file name will change. RIght now I get the fiel name from a textbox on a form...I am trying to change the below working code with a varaible instead of the path....I think there is some systax issues that I cannto fingure out

TotPath is the variable that holds the entire path to the file "X:Map_LibraryPark_and_Rec_AsbuiltPRA_19_73-01_W0.pdf"

This variable is rebuilt everytime the user selects something on the form....so the actual File name will change every time...

Does anyone have and ideas as to how to incorporate a variable instead of the hard coded path?

THank you all for your help.....


Code:WORKING CODE: 'Shell "C:Program FilesAdobeAcrobat 7.0AcrobatAcrobat.exe X:Map_LibraryPark_and_Rec_AsbuiltPRA_19_73-01_W0.pdf", vbMaximizedFocus ' open a txt documentNOT WORKING CODE:Shell "C:Program FilesAdobeAcrobat 7.0AcrobatAcrobat.exe TotPath", vbMaximizedFocus ' open a txt document

View 3 Replies View Related

Access97 SQL Syntax

Jul 25, 2005

I'm familiar with SQL but not with Access97 - some wierd syntax here!

I'm creating a Query that is to Delete records from a table depending on a non-key field in a second table.

I first tried an INNER JOIN


DELETE Activity_Preferences.*
FROM Activity_Preferences INNER JOIN Activity_Key
Activity_Preferences.Activity_Key=Activity_Key.Act ivity_Key AND Activity_Key.Complete=1;


which was initially accepted but then complained about the INNER JOIN after I went in a second time to 'fix' the error.

I've finally got the following syntax accepted:-


DELETE Activity_Preferences.*
FROM Activity_Preferences, Activity_Key
WHERE Activity_Preferences.Activity_Key=Activity_Key.Act ivity_Key AND Activity_Key.Complete=1;


But when executed still gets the following error (same as for the INNER JOIN):-

'Operation must use an updatable query'.

What else is needed?

J.
:confused:

View 4 Replies View Related

Syntax Question

Aug 1, 2005

Hi,
In a form i use the following filter fonction :
DoCmd.ApplyFilter , "CliNom = '" & RunCli & "'"
The problem is that sometimes RunCli (wich is a name) contains ' symbol and then generates a syntaxe error, is there a way to prevent that ?
Thanks in advance.
VINCENT

View 3 Replies View Related

Syntax Error

Mar 2, 2007

On my form I have 2 radio buttons rdoAll and rdoSpecific. If rdoAll is true then it prints a report. THis part works fine. However if rdoSpecific is true then I make visable combo box to look up an ID. Then when I click the button I want the same form to open but with just the info pertaining to the ID selected. Here is my code:

Private Sub cmdLotHistory_Click()

Dim stDocName As String, stSelection As String

stDocName = "rptLotHistory"

If Me.rdoAll = True Then
DoCmd.OpenReport "rptLotHistory", acViewPreview
End If

If Me.cboLotLU.Value > 0 Then
stSelection = "[LotID] =" & Me![cboLotLU]
End If

DoCmd.OpenReport stDocName, acViewPreview, , stSelection

End Sub

When I choose the ID and click the button I get the message

Run-Time error '3075':

Syntax error (missing operator) in query expression '(LotID
=020806B1585)'.

the 020806B1585 is my ID number.

Debug hightlights the
DoCmd.OpenReport stDocName, acViewPreview, , stSelection

but I'm guessing my real problem lies in the
stSelection = "[LotID] =" & Me![cboLotLU]


Can anyone point me in the right direction?

Thanks,
Rick

View 2 Replies View Related

SQL Syntax Issue

Jun 18, 2007

I am using the folling code in a after update combobox event:

Dim rst As DAO.Recordset
Dim sqlwhere As String

sqlwhere = " "

If IsNull(Me.comboSearchSerial) = False Then
sqlwhere = "SerialNumber='" & Me.comboSearchSerial & "' and "
End If


mysql = "SELECT TBL_RMA.* from [TBL_RMA] Where "
mysql = mysql & sqlwhere
mysql = mysql & ";"
Forms!FRM_RMA.RecordSource = mysql

Exit_comboSearchSerial_AfterUpdate:

This is currently working for me with SerialNumber being a text field. I would like to use the same code substituting SerialNumber with a Date field. I know its probly an issue with the use of quotes, but I can't seem to figure it out. Also, if I wanted to use a number format, what would I use...
Thanks
Gregg

View 2 Replies View Related

INVALID SQL Syntax

Sep 13, 2007

I am receiving this error;

"Invalid SQL syntax, cannot use multiple columns in a column level CHECK constraint."

Without explaining my disaster of a situation anyone have any ideas?

View 4 Replies View Related

Syntax Help On Rs.findfirst

Mar 25, 2008

Hi, I need some syntax help on the following line of code:

rs.FindFirst (rs![NewRecord] = True And IsNull(rs![Event_No]))

where NewRecord is type boolean and Event_No is string. Ive used this function mainly on strings so am not sure what to do with this one!
thanks!!

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved