 |
Access VBA Discuss using VBA for Access programming. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

October 13th, 2006, 04:11 AM
|
Registered User
|
|
Join Date: Oct 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
MS Data Grid control in ms access application
hi
first time i am into ms access application.in taht i need to add data's to ms datagrid manually.can anyone explain me how to do taht .i did the smae in visual basic by setting datasource and data memeber property of the datagrid .but here i dont know how to refer the tables in the same database.when i am trying to connect it by setting teh provider name and path,it is showing error database is currently locked .it si very urgent.can anyone help me !!!!
|

October 13th, 2006, 02:26 PM
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
Two things:
If you write this code and then immediately try to execute it, you may get an error that the database is put in a state by current user and can't do what you want. If that happens, save your code and then reopen the database and try your code again, but not from VBA, from the control or event you are coding.
Are you using ADO or DAO? Where is your data? Is it in the current mdb file, or in a remote file or DBMS?
mmcdonal
|

October 14th, 2006, 07:44 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
|
|
To refer to tables in the same database use CurrentProject.Connection. The following will set an ADO recordset as the data source of a Microsoft DataGrid Control 6.0 (SP6):
Code:
Private Sub Form_Load()
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim strSQL As String
Set cnn = CurrentProject.Connection
strSQL = "SELECT * FROM tblRecords"
Set rst = New ADODB.Recordset
rst.CursorLocation = adUseClient
rst.Open strSQL, cnn, adOpenStatic, adLockBatchOptimistic
Set grdDataGrid.DataSource = rst
End Sub
Oddly, the cursor type, cursor location, and lock type configuration I'm using appears to be absolutely the ONLY recordset configuration that gives the grid control a bookmarkable recordset that it can use as a datasource.
Anyway, good luck using ActiveX controls with Access/VBA. You're a braver man than me. Hope you have a copy of the VB6 help files around. I've gotten a bunch of ListView and TreeView controls fairly functional, but never did much with the DataGrid. Just don't have that much hair left to pull out.
HTH,
Bob
|

October 15th, 2006, 10:29 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
|
|
After some further tinkering with the cursor issue, what appears needed is a client-side cursor (which is always static).
|

October 16th, 2006, 02:30 AM
|
Registered User
|
|
Join Date: Oct 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hi Mr.mmcdonal and Mr.Bob Bedell ,
Thanks for your reply .but still it has problem.i am not able to enter data's to it .i mean it is not takking any value .i can point thh cursor in to each columns but what i am trying to enter it is not taking up.
i am using ADo connection for this
Set cnn = CurrentProject.Connection
strSQL = "select DimId,DimensionDesc,Dimension,Tolerance,DrawingShe et,DrawingZone from PartDetails"
rst.CursorLocation = adUseClient
rst.Open strSQL, cnn, adOpenStatic, adLockBatchOptimistic
Set dgdDetails.DataSource = rst
dgdDetails.Refresh
|

October 16th, 2006, 02:37 AM
|
Registered User
|
|
Join Date: Oct 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hi Mr.mmcdonal and Mr.Bob Bedell ,
Thanks for your reply .but still it has problem.i am not able to enter data's to it .i mean it is not takking any value .i can point the cursor in to each columns but what i am trying to enter it is not taking up.
i am using ADo connection for this
Set cnn = CurrentProject.Connection
strSQL = "select DimId,DimensionDesc,Dimension,Tolerance,DrawingShe et,DrawingZone from PartDetails"
rst.CursorLocation = adUseClient
rst.Open strSQL, cnn, adOpenStatic, adLockBatchOptimistic
Set dgdDetails.DataSource = rst
dgdDetails.Refresh
Will u be able to help me again :-)
Thanks,
Roshla
Quote:
quote:Originally posted by Bob Bedell
To refer to tables in the same database use CurrentProject.Connection. The following will set an ADO recordset as the data source of a Microsoft DataGrid Control 6.0 (SP6):
Code:
Private Sub Form_Load()
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim strSQL As String
Set cnn = CurrentProject.Connection
strSQL = "SELECT * FROM tblRecords"
Set rst = New ADODB.Recordset
rst.CursorLocation = adUseClient
rst.Open strSQL, cnn, adOpenStatic, adLockBatchOptimistic
Set grdDataGrid.DataSource = rst
End Sub
Oddly, the cursor type, cursor location, and lock type configuration I'm using appears to be absolutely the ONLY recordset configuration that gives the grid control a bookmarkable recordset that it can use as a datasource.
Anyway, good luck using ActiveX controls with Access/VBA. You're a braver man than me. Hope you have a copy of the VB6 help files around. I've gotten a bunch of ListView and TreeView controls fairly functional, but never did much with the DataGrid. Just don't have that much hair left to pull out.
HTH,
Bob
|
|
|
 |