|
-
Jul 2nd, 2012, 12:07 PM
#1
Thread Starter
New Member
How to load list box from Access Database
Hi !!
I want to load the data into List Box from Access Data base
How can i set it dynamically, so that i can select the values in the list box
-
Jul 2nd, 2012, 01:30 PM
#2
Re: How to load list box from Access Database
Welcome to the forums. 
What programming language are you using? Access VBA?
-
Jul 2nd, 2012, 08:24 PM
#3
Thread Starter
New Member
Re: How to load list box from Access Database
 Originally Posted by Hack
Welcome to the forums.
What programming language are you using? Access VBA?
Hi Hack,
Its in Excel User Forms List Box i want to load the data from Excel...
Code:
Dim db As Database, rs As Recordset, r As Long, dt As String
Set db = OpenDatabase("C:\Invoice\Invoice.mdb")
Set rs = db.OpenRecordset("InvoiceTbl", dbOpenTable)
With rs
.AddNew ' create a new record
dt = invmon.Value & "-" & invdt.Value & "-" & invyear.Value
.Fields("InvoiceDate") = dt
.Fields("CompanyID") = 1
' add more fields if necessary...
.Update ' stores the new record
End With
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
MsgBox "Data has been saved in access"
I am using the above code to store the data to Access From Excel, Similarly I am looking for info on how to load the data from Access to Excel Forms List Box.
-
Jul 2nd, 2012, 08:29 PM
#4
Thread Starter
New Member
Re: How to load list box from Access Database
Hi !!
I am using Excel Forms and want to load the data from Access to List Box and data can be selected from the List Box in forms.
Code:
Dim db As Database, rs As Recordset, r As Long, dt As String
' connect to the Access database
' Set cn = New ADODB.Connection
Set db = OpenDatabase("C:\Invoice\Invoice.mdb")
' open the database
Set rs = db.OpenRecordset("InvoiceTbl", dbOpenTable)
With rs
.AddNew ' create a new record
' add values to each field in the record
dt = invmon.Value & "-" & invdt.Value & "-" & invyear.Value
.Fields("InvoiceDate") = dt
.Fields("CompanyID") = 1
' add more fields if necessary...
.Update ' stores the new record
End With
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
MsgBox "Data has been saved in access"
I am using above code to store the data into Access from Excel...
Now i want to show the data to List Box of User Forms by getting the data from Access DB.
-
Jul 3rd, 2012, 06:10 AM
#5
Re: How to load list box from Access Database
Excel VBA question moved to Office Development
-
Jul 3rd, 2012, 08:48 PM
#6
Thread Starter
New Member
Re: How to load list box from Access Database
Team,
Any updates on this request... How can i show the Access data in the Excel List Box of User Forms... I had posted the code which i am using to store the data from Excel to List Box but how could i do the reverse of it...
-
Jul 4th, 2012, 05:15 AM
#7
Re: How to load list box from Access Database
vb Code:
Set db = OpenDatabase("C:\Invoice\Invoice.mdb") ' open the database Set rs = db.OpenRecordset("InvoiceTbl", dbOpenTable) ' first part stays the same do until rs.eof listbox1.additem rs(f) ' where f is the index of the field to fill the listbox rs.movenext loop
alternatively you can use an sql query to populate the recordset, with only the desired results from the table
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jul 4th, 2012, 06:03 AM
#8
Re: How to load list box from Access Database
sql query something like this to open only where the field name 'FirstName' has 'seenu'
Code:
Set rs = db.OpenRecordset("select * from MyTable where FirstName='seenu'")
-
Jul 5th, 2012, 10:56 AM
#9
Thread Starter
New Member
Re: How to load list box from Access Database
Hi Seenu,
I was trying to access using the SQL but was getting TypeMismatch issue....
Code:
Dim db As Database, rs As Recordset, r As Long
Set db = OpenDatabase("C:\Invoice\Invoice.mdb")
Set rs = db.OpenRecordset("select BName from BrokerTbl")
Do Until rs.EOF
Invoice_Preparation.brokername.AddItem rs
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
-
Jul 5th, 2012, 11:02 AM
#10
Re: How to load list box from Access Database
kiran, try like this
Code:
Invoice_Preparation.brokername.AddItem rs!BName
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|