473,396 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Something's Wrong with this code!!

I have a form that has 2 types of selection boxes at the top (Number or
Name) and a listbox on the bottom to show the results.

If the user chooses a single PO#, just that PO will (Should!) show in
the list box below. If they choose a Name, then all the POs for that
person should show in the list box.

I planned to call a function, passing the "type" as text (name or
number) and the "key" (one PO# or the table key associated with the
name), and build the Where clause and the SQL string for the list box
accordingly.

It's not working. If I put the code directly in the form in the
RowSource for the ListBox, I can get data in the list box. But (what
looks to me to be) the same code as code doesn't work.

When I step through the code, I see the variables are being passed
correctly; just nothing shows up in the list box. I've tried
adding/removing parenthesis, nothing works.

Thanks. I really thought I'd be able to do this....
Sara

(code below):

In the form - RowSource for the listbox:

SELECT tblPOData.POKey, tblPOData.PONum, tblPOData.PODate,
tblMerchant.MerchFirstName, tblVendors.Vendor, tblPOData.Description
FROM (tblPOData LEFT JOIN tblVendors ON tblPOData.VendorKey =
tblVendors.VendorKey) LEFT JOIN tblMerchant ON tblPOData.MerchantKey =
tblMerchant.MerchantKey WHERE
(((tblMerchant.MerchantKey)=[Forms]![frmSelectPO]![cboMerchKey]));
Function:
Public Function fcnLoadPOList(lngKey As Long, strSource As String) As
Boolean
On Error GoTo Err_fcnLoadPOList

' Load the PO list with either the PO number from the combo box
' or all the POs for the Merchant from the combo box (in desc
POdate order)

Dim strSQLPO As String
Dim strSQLMerch As String

fcnLoadPOList = False

If strSource = "Merch" Then
strSQLMerch = "SELECT tblPOData.POKey, tblPOData.PONum,
tblPOData.PODate, " _
& " tblMerchant.MerchFirstName, tblVendors.Vendor,
tblPOData.Description " _
& " FROM tblPOData " _
& " LEFT JOIN (tblVendors " _
& " ON tblPOData.VendorKey = " & " tblVendors.VendorKey) "
_
& " LEFT JOIN tblMerchant " _
& " ON tblPOData.MerchantKey = " & "
tblMerchant.MerchantKey " _
& " WHERE (tblMerchant.MerchantKey = " & lngKey & ")" _
& " ORDER BY tblPOData.PODate DESC "

Forms!frmSelectPO.lstPOs.RowSource = strSQLMerch
Forms!frmSelectPO.lstPOs.Requery

Else
strSQLPO = "SELECT tblPOData.POKey, tblPOData.PONum, " _
& " tblPOData.PODate, tblMerchant.MerchFirstName, " _
& " tblVendors.Vendor, tblPOData.Description " _
& " FROM tblPOData " _
& " LEFT JOIN tblVendors " _
& " ON tblPOData.VendorKey = " & "tblVendors.VendorKey " _
& " LEFT JOIN tblMerchant " _
& " ON tblPOData.MerchantKey = " &
"tblMerchant.MerchantKey " _
& " WHERE (tblPOData.POKey = " & lngKey & ")" _
& " OrderBy tblPOData.PODate DESC;"

Forms!frmSelectPO.lstPOs.RowSource = strSQLPO
Forms!frmSelectPO.lstPOs.Requery
End If

fcnLoadPOList = True

Dec 11 '06 #1
4 1105
When you have populated the try refreshing the records, i.e.
docmd.runcommand accmdrefresh

Hope this helps

Dean

"sara" <sa*******@yahoo.comwrote in message
news:11**********************@j72g2000cwa.googlegr oups.com...
>I have a form that has 2 types of selection boxes at the top (Number or
Name) and a listbox on the bottom to show the results.

If the user chooses a single PO#, just that PO will (Should!) show in
the list box below. If they choose a Name, then all the POs for that
person should show in the list box.

I planned to call a function, passing the "type" as text (name or
number) and the "key" (one PO# or the table key associated with the
name), and build the Where clause and the SQL string for the list box
accordingly.

It's not working. If I put the code directly in the form in the
RowSource for the ListBox, I can get data in the list box. But (what
looks to me to be) the same code as code doesn't work.

When I step through the code, I see the variables are being passed
correctly; just nothing shows up in the list box. I've tried
adding/removing parenthesis, nothing works.

Thanks. I really thought I'd be able to do this....
Sara

(code below):

In the form - RowSource for the listbox:

SELECT tblPOData.POKey, tblPOData.PONum, tblPOData.PODate,
tblMerchant.MerchFirstName, tblVendors.Vendor, tblPOData.Description
FROM (tblPOData LEFT JOIN tblVendors ON tblPOData.VendorKey =
tblVendors.VendorKey) LEFT JOIN tblMerchant ON tblPOData.MerchantKey =
tblMerchant.MerchantKey WHERE
(((tblMerchant.MerchantKey)=[Forms]![frmSelectPO]![cboMerchKey]));
Function:
Public Function fcnLoadPOList(lngKey As Long, strSource As String) As
Boolean
On Error GoTo Err_fcnLoadPOList

' Load the PO list with either the PO number from the combo box
' or all the POs for the Merchant from the combo box (in desc
POdate order)

Dim strSQLPO As String
Dim strSQLMerch As String

fcnLoadPOList = False

If strSource = "Merch" Then
strSQLMerch = "SELECT tblPOData.POKey, tblPOData.PONum,
tblPOData.PODate, " _
& " tblMerchant.MerchFirstName, tblVendors.Vendor,
tblPOData.Description " _
& " FROM tblPOData " _
& " LEFT JOIN (tblVendors " _
& " ON tblPOData.VendorKey = " & " tblVendors.VendorKey) "
_
& " LEFT JOIN tblMerchant " _
& " ON tblPOData.MerchantKey = " & "
tblMerchant.MerchantKey " _
& " WHERE (tblMerchant.MerchantKey = " & lngKey & ")" _
& " ORDER BY tblPOData.PODate DESC "

Forms!frmSelectPO.lstPOs.RowSource = strSQLMerch
Forms!frmSelectPO.lstPOs.Requery

Else
strSQLPO = "SELECT tblPOData.POKey, tblPOData.PONum, " _
& " tblPOData.PODate, tblMerchant.MerchFirstName, " _
& " tblVendors.Vendor, tblPOData.Description " _
& " FROM tblPOData " _
& " LEFT JOIN tblVendors " _
& " ON tblPOData.VendorKey = " & "tblVendors.VendorKey " _
& " LEFT JOIN tblMerchant " _
& " ON tblPOData.MerchantKey = " &
"tblMerchant.MerchantKey " _
& " WHERE (tblPOData.POKey = " & lngKey & ")" _
& " OrderBy tblPOData.PODate DESC;"

Forms!frmSelectPO.lstPOs.RowSource = strSQLPO
Forms!frmSelectPO.lstPOs.Requery
End If

fcnLoadPOList = True

Dec 12 '06 #2
This is not working. I am getting "The command or action Refresh isn't
available now"

Any other ideas? This is killing me!

Sara
Dean Spencer wrote:
When you have populated the try refreshing the records, i.e.
docmd.runcommand accmdrefresh

Hope this helps

Dean

"sara" <sa*******@yahoo.comwrote in message
news:11**********************@j72g2000cwa.googlegr oups.com...
I have a form that has 2 types of selection boxes at the top (Number or
Name) and a listbox on the bottom to show the results.

If the user chooses a single PO#, just that PO will (Should!) show in
the list box below. If they choose a Name, then all the POs for that
person should show in the list box.

I planned to call a function, passing the "type" as text (name or
number) and the "key" (one PO# or the table key associated with the
name), and build the Where clause and the SQL string for the list box
accordingly.

It's not working. If I put the code directly in the form in the
RowSource for the ListBox, I can get data in the list box. But (what
looks to me to be) the same code as code doesn't work.

When I step through the code, I see the variables are being passed
correctly; just nothing shows up in the list box. I've tried
adding/removing parenthesis, nothing works.

Thanks. I really thought I'd be able to do this....
Sara

(code below):

In the form - RowSource for the listbox:

SELECT tblPOData.POKey, tblPOData.PONum, tblPOData.PODate,
tblMerchant.MerchFirstName, tblVendors.Vendor, tblPOData.Description
FROM (tblPOData LEFT JOIN tblVendors ON tblPOData.VendorKey =
tblVendors.VendorKey) LEFT JOIN tblMerchant ON tblPOData.MerchantKey =
tblMerchant.MerchantKey WHERE
(((tblMerchant.MerchantKey)=[Forms]![frmSelectPO]![cboMerchKey]));
Function:
Public Function fcnLoadPOList(lngKey As Long, strSource As String) As
Boolean
On Error GoTo Err_fcnLoadPOList

' Load the PO list with either the PO number from the combo box
' or all the POs for the Merchant from the combo box (in desc
POdate order)

Dim strSQLPO As String
Dim strSQLMerch As String

fcnLoadPOList = False

If strSource = "Merch" Then
strSQLMerch = "SELECT tblPOData.POKey, tblPOData.PONum,
tblPOData.PODate, " _
& " tblMerchant.MerchFirstName, tblVendors.Vendor,
tblPOData.Description " _
& " FROM tblPOData " _
& " LEFT JOIN (tblVendors " _
& " ON tblPOData.VendorKey = " & " tblVendors.VendorKey) "
_
& " LEFT JOIN tblMerchant " _
& " ON tblPOData.MerchantKey = " & "
tblMerchant.MerchantKey " _
& " WHERE (tblMerchant.MerchantKey = " & lngKey & ")" _
& " ORDER BY tblPOData.PODate DESC "

Forms!frmSelectPO.lstPOs.RowSource = strSQLMerch
Forms!frmSelectPO.lstPOs.Requery

Else
strSQLPO = "SELECT tblPOData.POKey, tblPOData.PONum, " _
& " tblPOData.PODate, tblMerchant.MerchFirstName, " _
& " tblVendors.Vendor, tblPOData.Description " _
& " FROM tblPOData " _
& " LEFT JOIN tblVendors " _
& " ON tblPOData.VendorKey = " & "tblVendors.VendorKey " _
& " LEFT JOIN tblMerchant " _
& " ON tblPOData.MerchantKey = " &
"tblMerchant.MerchantKey " _
& " WHERE (tblPOData.POKey = " & lngKey & ")" _
& " OrderBy tblPOData.PODate DESC;"

Forms!frmSelectPO.lstPOs.RowSource = strSQLPO
Forms!frmSelectPO.lstPOs.Requery
End If

fcnLoadPOList = True
Dec 12 '06 #3
First, I wouldn't set up two different strSQL variables. I'd set up
something like the following:

Dim strSQL As String

fcnLoadPOList = False

If strSource = "Merch" Then
strSQL = "SELECT tblPOData.POKey, tblPOData.PONum,
blah blah blah
Else
strSQL = "SELECT tblPOData.POKey, tblPOData.PONum, " _
blah blah blah
End If

Forms!frmSelectPO.lstPOs.RowSource = strSQL
Forms!frmSelectPO.lstPOs.Requery

End If

which is a little simpler and easier to maintain. That being said, I'd
put a debug.print line after my first End If as follows:

debug.print strSQL

Then I would
1. run the form
2 copy whatever gets printed out by the debug.print statement (press
ctrl G first if you don't see the debug window)
3. open a new query window in SQL view
4. paste what you copied in step 1 into the new query window and run
it.

I suspect that when you perform step 4 you'll find a syntax error or
some such that Access didn't tell you about.

Bruce

Dec 12 '06 #4
Thank you, Thank you, Thank you!!!!

I carefully followed your steps (starting with neatening up the code,
thank you), and found a join error, then a syntax error when trying to
fix the join.

Bottom line - I started over, with the Debug.Print and voila! I can
now move on to the next piece of development.

Many thanks.

Sara

de***************@gmail.com wrote:
First, I wouldn't set up two different strSQL variables. I'd set up
something like the following:

Dim strSQL As String

fcnLoadPOList = False

If strSource = "Merch" Then
strSQL = "SELECT tblPOData.POKey, tblPOData.PONum,
blah blah blah
Else
strSQL = "SELECT tblPOData.POKey, tblPOData.PONum, " _
blah blah blah
End If

Forms!frmSelectPO.lstPOs.RowSource = strSQL
Forms!frmSelectPO.lstPOs.Requery

End If

which is a little simpler and easier to maintain. That being said, I'd
put a debug.print line after my first End If as follows:

debug.print strSQL

Then I would
1. run the form
2 copy whatever gets printed out by the debug.print statement (press
ctrl G first if you don't see the debug window)
3. open a new query window in SQL view
4. paste what you copied in step 1 into the new query window and run
it.

I suspect that when you perform step 4 you'll find a syntax error or
some such that Access didn't tell you about.

Bruce
Dec 12 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Vic | last post by:
Dear All, I found this code snippet on this list (taken from a nice webpage of a courteous fellow), which I used to filter a form on a combo box. I wanted to repeat the same code to have an...
5
by: cc0064263 | last post by:
hello, i am very new to C and i am reading K&R and i came accross this code in the book. K&R says that it is incorrect to free something after it has been freed and gives this as an example. ...
6
by: Niklaus | last post by:
Hi, Can someone point out what is wrong with this code ? How can i make it better optimize it. When run it gives me seg fault in linux. But windows it works fine(runs for a long time). Do we...
2
by: Rui Macdonald | last post by:
What is wrong with this code to populate a DropDownList? Can somebody Help me? Tnx RMac ===================================================================================== WebForm.aspx.vb
6
by: doncee | last post by:
This is the set up: is a date field on a form. Its control source is the field "date_entered" in"Table1". If there is a date showing in the date_entered field (Text6) & the status in Combo box2...
28
by: hijkl | last post by:
hey guys anything wrong with this code?? if it is then what? int *array(int n){ return new int(n); } int main(){ int *p = array(10); for( int i = 0; i < 10; i++ ) {
5
by: Jeff | last post by:
ASP.NET 2.0 This code crashes. It generate this error: Value cannot be null. Parameter name: type I've created some custom web.config settings and this crash is related to accessing theme...
3
by: Koliber (js) | last post by:
I feel i still do not understand maybe a bit a dispose pattern So I have a question - is this code right? Is fs.Close() there where it is right? If I do understand it in place 'BBB' there can be a...
5
by: hiqu | last post by:
This issue is driving me nuts and not able to figure out whats wrong. I've this code in my firefox extension. Firefox always hangs and reports the script is busy. if I introduce a break...
2
by: ccgrl451 | last post by:
Okay, so you probably haven't seen my previous question, whats wrong with this code. For those who have, you know what I'm talking about. If not, heres what I have to do. We have to do this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.