Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying data with data control, help!!

Status
Not open for further replies.

kiramoto

Programmer
May 13, 2002
9
BR
I did something like this :

CommonDialog1.ShowOpen
PlanName = CommonDialog1.Filename 'open my worksheet
Data1.DatabaseName = PlanName
Data1.RecordSource = "Plan1"

and there is a MSFLEXGRID which property DataSource = Data1

It doesn't work. Can anyone help me?
Thanks in advance,
 
Here is some nice and neat code to open a dialog & select a mdb file.

Remember to set the DatabaseName(mdb) & RecordSource(table) of Data1 in properties window.

Private Sub Form_Load()

On Error GoTo Handle_Error

With Data1
.DatabaseName = App.Path & "\YourTable.mdb"
.Refresh
.Recordset.MoveLast
.Recordset.MoveFirst
End With

Handle_Error:
Dim strNewDatabaseName As String
Dim intResponse As Integer

Select Case Err.Number
Case 3004, 3024, 3044
strNewDatabaseName = GetNewDatabaseName
If strNewDatabaseName = "" Then
Unload Me
Else
Data1.DatabaseName = strNewDatabaseName
End If
Case Else
intResponse = MsgBox(Err.Description, vbRetryCancel + _
vbExclamation, "Unexpected Database Error")
If intResponse = vbRetry Then
Form_Load
Else
Unload Me
End If
End Select

End Sub

Private Function GetNewDatabaseName()

Dim intResponse As Integer
Dim strMsg As String

strMsg = "Database file not found." & vbCrLf & vbCrLf & _
"Do you want to lacate the file?"
intResponse = MsgBox(strMsg, vbYesNo + vbQuestion, _
"File or path not found.")
If intResponse = vbNo Then
GetNewDatabaseName = ""
Else
With dlgOpen
.FileName = Data1.DatabaseName
.Filter = "Database files (*.mdb)|*.mdb|All files (*.*)|*.*"
On Error Resume Next
.ShowOpen
If Err.Number = cdlCancel Then
GetNewDatabaseName = ""
Else
GetNewDatabaseName = .FileName
End If
End With
End If

End Function

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top