OnOpen Oederby

G

GracieLou

I have read numerous postings and have tried nearly as many with no results.

I have a form being opened from my frmMain. The record source is the same,
but, depending on the button clicked the form needs to sort differently. The
fields to be sorted are either VndrNbr [asc], VndrNm [asc], or Amt [desc].
When a button on frmMain is click SortSw is set to a value, 0=VndrNbr,
1=VndrNm, and 2=Amt, and the frmVndrLst is opened.

In the OnOpen for frmVndrLst I have
If SortSw = 0 then
Me.OrderBy = VndrNbr
Elseif SortSw = 1 then
Me.oderby = VndrNm
Elseif SortSw = 2 then
Me.OrderBy = Amt [desc]
End If.
Me.OderByOn = True

When I click on VndrNbr I get a parameter box asking for the VndrNbr. It
has the tables first VndrNbr showing above the box's imput area. I just
click OK and the form opens but is not sorted. Weh I click on the Name
button i get a parameter box with the form that is opening, frmVndrLst, above
the box's input area.

I am throughly confused. Can someone please help.

Thank You.
 
D

Douglas J. Steele

I believe that the Open event is too soon to try and sort the data: the
form's RecordSource hasn't been populated yet.

Try putting that code into the Load event.
 
D

Dirk Goldgar

GracieLou said:
I have read numerous postings and have tried nearly as many with no
results.

I have a form being opened from my frmMain. The record source is the
same,
but, depending on the button clicked the form needs to sort differently.
The
fields to be sorted are either VndrNbr [asc], VndrNm [asc], or Amt [desc].
When a button on frmMain is click SortSw is set to a value, 0=VndrNbr,
1=VndrNm, and 2=Amt, and the frmVndrLst is opened.

In the OnOpen for frmVndrLst I have
If SortSw = 0 then
Me.OrderBy = VndrNbr
Elseif SortSw = 1 then
Me.oderby = VndrNm
Elseif SortSw = 2 then
Me.OrderBy = Amt [desc]
End If.
Me.OderByOn = True

When I click on VndrNbr I get a parameter box asking for the VndrNbr. It
has the tables first VndrNbr showing above the box's imput area. I just
click OK and the form opens but is not sorted. Weh I click on the Name
button i get a parameter box with the form that is opening, frmVndrLst,
above
the box's input area.

I am throughly confused. Can someone please help.


The OrderBy property is a string property; you have to give it the names of
the fields as string literals. Try this:

If SortSw = 0 then
Me.OrderBy = "VndrNbr"
Elseif SortSw = 1 then
Me.OrderBy = "VndrNm"
Elseif SortSw = 2 then
Me.OrderBy = "Amt DESC"
End If.
Me.OrderByOn = True
 
G

GracieLou

You guys are great.

I don't understand why it works this way, but it sorks!

thanks!

Dirk Goldgar said:
GracieLou said:
I have read numerous postings and have tried nearly as many with no
results.

I have a form being opened from my frmMain. The record source is the
same,
but, depending on the button clicked the form needs to sort differently.
The
fields to be sorted are either VndrNbr [asc], VndrNm [asc], or Amt [desc].
When a button on frmMain is click SortSw is set to a value, 0=VndrNbr,
1=VndrNm, and 2=Amt, and the frmVndrLst is opened.

In the OnOpen for frmVndrLst I have
If SortSw = 0 then
Me.OrderBy = VndrNbr
Elseif SortSw = 1 then
Me.oderby = VndrNm
Elseif SortSw = 2 then
Me.OrderBy = Amt [desc]
End If.
Me.OderByOn = True

When I click on VndrNbr I get a parameter box asking for the VndrNbr. It
has the tables first VndrNbr showing above the box's imput area. I just
click OK and the form opens but is not sorted. Weh I click on the Name
button i get a parameter box with the form that is opening, frmVndrLst,
above
the box's input area.

I am throughly confused. Can someone please help.


The OrderBy property is a string property; you have to give it the names of
the fields as string literals. Try this:

If SortSw = 0 then
Me.OrderBy = "VndrNbr"
Elseif SortSw = 1 then
Me.OrderBy = "VndrNm"
Elseif SortSw = 2 then
Me.OrderBy = "Amt DESC"
End If.
Me.OrderByOn = True


--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
C

Cheese_whiz

Hi GracieLou,

Quick translation of two lines of code, the first from you and the second
from dirk:

Your Code: Me.Orderby = VndrNbr
Translation: The Orderby property of the current form is equal to the value
of the variable named VndrNbr.

Dirks Code: Me.Orderby = "VndrNbr"
Translation: The Orderby property of the current formis equal to VndrNbr.

See, without the quotation marks, access thinks VndrNbr is a variable and
tries to figure out with the value of that variable is. With them, Access
knows that you want to actually use those characters/letters (that string) as
the value of the Orderby property....

Does that help any?
CW

GracieLou said:
You guys are great.

I don't understand why it works this way, but it sorks!

thanks!

Dirk Goldgar said:
GracieLou said:
I have read numerous postings and have tried nearly as many with no
results.

I have a form being opened from my frmMain. The record source is the
same,
but, depending on the button clicked the form needs to sort differently.
The
fields to be sorted are either VndrNbr [asc], VndrNm [asc], or Amt [desc].
When a button on frmMain is click SortSw is set to a value, 0=VndrNbr,
1=VndrNm, and 2=Amt, and the frmVndrLst is opened.

In the OnOpen for frmVndrLst I have
If SortSw = 0 then
Me.OrderBy = VndrNbr
Elseif SortSw = 1 then
Me.oderby = VndrNm
Elseif SortSw = 2 then
Me.OrderBy = Amt [desc]
End If.
Me.OderByOn = True

When I click on VndrNbr I get a parameter box asking for the VndrNbr. It
has the tables first VndrNbr showing above the box's imput area. I just
click OK and the form opens but is not sorted. Weh I click on the Name
button i get a parameter box with the form that is opening, frmVndrLst,
above
the box's input area.

I am throughly confused. Can someone please help.


The OrderBy property is a string property; you have to give it the names of
the fields as string literals. Try this:

If SortSw = 0 then
Me.OrderBy = "VndrNbr"
Elseif SortSw = 1 then
Me.OrderBy = "VndrNm"
Elseif SortSw = 2 then
Me.OrderBy = "Amt DESC"
End If.
Me.OrderByOn = True


--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top