473,398 Members | 2,427 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,398 software developers and data experts.

How to Refresh List Box - Sounds Simple???

I am using the following module code to display in a List Box all
attached tables that start with tblProducts i.e. tblProductsSpain or
tblProductsFrance etc

I have other code which enables the user to enter a new table name,
the code then creates the table in the attached back end database and
automatically links it to the front end.

My problem is that the list box does not display the new tables until
I close the program and restart it. Requery has no effect, is there a
way of forcing a refresh?

Thanks
Patrick


Function ListAllTables(fld As Control, ID As Long, row As _
Long, col As Long, Code As Integer)
Dim Db As Database
Dim tbdf As TableDef
Static tbls(256) As String
Static Entries As Integer
Dim i As Integer
Dim ReturnVal
ReturnVal = Null
Select Case Code
Case LB_INITIALIZE ' Initialize database.
Set Db = DBEngine.Workspaces(0).Databases(0)
Entries = 0
For i = 0 To Db.TableDefs.Count - 1
If Left(Db.TableDefs(i).Name, 11) = "tblProducts" And
Db.TableDefs(i).Name <> "tblProducts" And Db.TableDefs(i).Name <>
"tblProductsHTML" And Db.TableDefs(i).Name <>
"tblProductsEndOfYearArchive" Then
tbls(Entries) = Db.TableDefs(i).Name
Entries = Entries + 1
End If
Next i
ReturnVal = Entries
Case LB_OPEN ' Open.
ReturnVal = Timer ' Unique ID number for control.
Case LB_GETROWCOUNT ' Number of rows.
ReturnVal = Entries
Case LB_GETCOLUMNCOUNT ' Number of columns.
ReturnVal = 1
Case LB_GETCOLUMNWIDTH ' Column width.
ReturnVal = -1 ' Use the default width.
Case LB_GETVALUE ' Get the data.
If Left(tbls(row), 11) = "tblProducts" Then
ReturnVal = tbls(row)
End If
Case LB_END ' End.
For Entries = 0 To 256
tbls(Entries) = ""
Next
End Select
ListAllTables = ReturnVal
End Function
Nov 13 '05 #1
2 7852
That's correct. The static array will not reinitialize until you close the
form.

The best solution might be to normalize the tables. Instead creating a new
table for every country, consider using a tblProductDetail table with these
fields:
ProductID foreign key to tblProducts.ProductID
CountryID foreign key to tblCountry.CountryID
UnitPrice Currency (the currency symbol will be in tblCountry).
TaxRate Double (because some countries have different tax rates
for different products).
ProductName Text (what the product is called in this country).

Now all you have to do is set the RowSource of the listbox to a new query
statement that retrieves the product names used by the country (WHERE
CountryID = 99), and the prices for that country, using the custom currency
format string you stored in the tblCountry table.

If desired, you can use the AfterUpdate and AfterDelConfirm event procedures
of the form where product details are entered to see if the form with the
list box is open, and if so, Requery the list box so it shows the new
product or changed price.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Patrick Fisher" <in**@psoftuk.com> wrote in message
news:uf********************************@4ax.com...
I am using the following module code to display in a List Box all
attached tables that start with tblProducts i.e. tblProductsSpain or
tblProductsFrance etc

I have other code which enables the user to enter a new table name,
the code then creates the table in the attached back end database and
automatically links it to the front end.

My problem is that the list box does not display the new tables until
I close the program and restart it. Requery has no effect, is there a
way of forcing a refresh?

Thanks
Patrick
Function ListAllTables(fld As Control, ID As Long, row As _
Long, col As Long, Code As Integer)
Dim Db As Database
Dim tbdf As TableDef
Static tbls(256) As String
Static Entries As Integer
Dim i As Integer
Dim ReturnVal
ReturnVal = Null
Select Case Code
Case LB_INITIALIZE ' Initialize database.
Set Db = DBEngine.Workspaces(0).Databases(0)
Entries = 0
For i = 0 To Db.TableDefs.Count - 1
If Left(Db.TableDefs(i).Name, 11) = "tblProducts" And
Db.TableDefs(i).Name <> "tblProducts" And Db.TableDefs(i).Name <>
"tblProductsHTML" And Db.TableDefs(i).Name <>
"tblProductsEndOfYearArchive" Then
tbls(Entries) = Db.TableDefs(i).Name
Entries = Entries + 1
End If
Next i
ReturnVal = Entries
Case LB_OPEN ' Open.
ReturnVal = Timer ' Unique ID number for control.
Case LB_GETROWCOUNT ' Number of rows.
ReturnVal = Entries
Case LB_GETCOLUMNCOUNT ' Number of columns.
ReturnVal = 1
Case LB_GETCOLUMNWIDTH ' Column width.
ReturnVal = -1 ' Use the default width.
Case LB_GETVALUE ' Get the data.
If Left(tbls(row), 11) = "tblProducts" Then
ReturnVal = tbls(row)
End If
Case LB_END ' End.
For Entries = 0 To 256
tbls(Entries) = ""
Next
End Select
ListAllTables = ReturnVal
End Function

Nov 13 '05 #2
Thanks for your suggestion Allen, with hindsight that was obviously a
much better way to do it.
Patrick
Nov 13 '05 #3

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

Similar topics

1
by: Silky | last post by:
Iam trying to get the green footer div to sit on the bottom of all three divs so as the divs vary in height it sits off the bottom of the lowest one I cannot use absolutes because the three...
4
by: Jürgen Devlieghere | last post by:
We encounter a crash every now and then at a client, and now I'm starting to doubt the fundamentals of life :-) We have a list of structs. struct SContactProperty { public:...
2
by: SubhaBabu | last post by:
How to display a msg in the same page....document.write opens in a new page when i am using in the link....but i want to display in the same page.
5
by: Sean Byrne | last post by:
We have a Microsoft Access 2000 database consisting of 20 tables covering 20 different events. In each table, there are 3 Team members, a date of the event and several unique fields for the event,...
3
by: John Baker | last post by:
Hi:7 Newby here to ASP, and using the ASP.NET Web Matrix development tool. While that tool looks great for a Newby, I have run into a snag. I have an HTML Text Box which I have named HireInput,...
1
by: turf236 | last post by:
I was wondering if someone could assist witht he code needed to work with refreshing a list box created off of a table. I need the list box to refreshed when I click the delete button that I also...
5
by: SA SA | last post by:
Is this possible? I have three items in drop down "Select Payment Type", "Credit Card" and "Check". if user select Credit card then i need to post the form variables to different URL than check...
5
by: =?iso-8859-1?B?QW5kcukgSORuc2Vs?= | last post by:
Hi, this is another problem that tempts me to use tables but before I do that I'm going to ask you. Sounds simple: A list of images with a description to their right. Illustration:...
1
by: mdpems | last post by:
Hi, I have a combo box that is set up to receive items from another from and post as a record set. The items will post to the list as I click an add item button. I also have a remove item button. I...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.