Access VBADiscuss 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
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 !!!!
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?
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.
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
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.