tnguyen315
MIS
Hello,
I have a question, don’t know if it’s possible …
First, I have a form with 2 text fields and “BeginDate” and “EndDate” and a button “cmdRunQuery”. When the user enter data into 2 text fields with date format “MM/DD/YYYY”, and hit “ Run Query” . It’s working fine and run a make table query on the external database on network. However, my concern is if somehow, someone delete the database on network, then I get the error when running the make table query.
So Is there anyway to check the database on network first?, If the database exist then, run make table query. If the database is not exist, then create a new database on the same location and then run make table query. The database is on K drive, K:\Custom\IVD\Main\AccessSQL\AHD.mdb
Below is my code for run make table query. (Run make 4 tables at the same time, tblA, tblB, tblC and tblD)
Private Sub cmdRunQuery_Click()
On Error GoTo Err_cmdRunQuery__Click
Dim stDocName1 As String
Dim stDocName2 As String
Dim stDocName3 As String
Dim stDocName4 As String
Dim rst As Recordset
Dim wsp As Workspace
If IsNull(Me.BeginDate) Or (Me.BeginDate) = "" Then
MsgBox "Please Enter Begin Date!", vbOKOnly, "Invalid Criterion!"
Me![BeginDate].SetFocus
Exit Sub
ElseIf IsNull(Me.EndDate) Or (Me.EndDate) = "" Then
MsgBox "Please Enter End Date!", vbOKOnly, "Invalid Criterion!"
Me![EndDate].SetFocus
Exit Sub
Else
I WOULD LIKE SOME CODE RIGHT HERE BUT DON”T KNOW HOW…
IF THE DATABASE “AHD.mdb” IS NOT EXIST THEN
CREATE NEW DATABASE on K:\Custom\IVD\Main\AccessSQL\AHD.mdb
ELSE ‘run code below
DoCmd.SetWarnings False
DoCmd.Hourglass True
stDocName1 = "qry_MakeTableA"
stDocName2 = "qry_MakeTableB"
stDocName3 = "qry_MakeTableC"
stDocName4 = "qry_MakeTableD"
DoCmd.OpenQuery stDocName1, acNormal, acEdit
DoCmd.OpenQuery stDocName2, acNormal, acEdit
DoCmd.OpenQuery stDocName3, acNormal, acEdit
DoCmd.OpenQuery stDocName4, acNormal, acEdit
DoCmd.SetWarnings True
DoCmd.Hourglass False
MsgBox ("Actions Completed!")
ENDIF
End If
Exit_cmdRunQuery__Click:
Exit Sub
Err_cmdRunQuery__Click:
MsgBox Err.Description
Resume Exit_cmdRunQuery__Click
End Sub
Please help, I’m very appreciated. Thanks
I have a question, don’t know if it’s possible …
First, I have a form with 2 text fields and “BeginDate” and “EndDate” and a button “cmdRunQuery”. When the user enter data into 2 text fields with date format “MM/DD/YYYY”, and hit “ Run Query” . It’s working fine and run a make table query on the external database on network. However, my concern is if somehow, someone delete the database on network, then I get the error when running the make table query.
So Is there anyway to check the database on network first?, If the database exist then, run make table query. If the database is not exist, then create a new database on the same location and then run make table query. The database is on K drive, K:\Custom\IVD\Main\AccessSQL\AHD.mdb
Below is my code for run make table query. (Run make 4 tables at the same time, tblA, tblB, tblC and tblD)
Private Sub cmdRunQuery_Click()
On Error GoTo Err_cmdRunQuery__Click
Dim stDocName1 As String
Dim stDocName2 As String
Dim stDocName3 As String
Dim stDocName4 As String
Dim rst As Recordset
Dim wsp As Workspace
If IsNull(Me.BeginDate) Or (Me.BeginDate) = "" Then
MsgBox "Please Enter Begin Date!", vbOKOnly, "Invalid Criterion!"
Me![BeginDate].SetFocus
Exit Sub
ElseIf IsNull(Me.EndDate) Or (Me.EndDate) = "" Then
MsgBox "Please Enter End Date!", vbOKOnly, "Invalid Criterion!"
Me![EndDate].SetFocus
Exit Sub
Else
I WOULD LIKE SOME CODE RIGHT HERE BUT DON”T KNOW HOW…
IF THE DATABASE “AHD.mdb” IS NOT EXIST THEN
CREATE NEW DATABASE on K:\Custom\IVD\Main\AccessSQL\AHD.mdb
ELSE ‘run code below
DoCmd.SetWarnings False
DoCmd.Hourglass True
stDocName1 = "qry_MakeTableA"
stDocName2 = "qry_MakeTableB"
stDocName3 = "qry_MakeTableC"
stDocName4 = "qry_MakeTableD"
DoCmd.OpenQuery stDocName1, acNormal, acEdit
DoCmd.OpenQuery stDocName2, acNormal, acEdit
DoCmd.OpenQuery stDocName3, acNormal, acEdit
DoCmd.OpenQuery stDocName4, acNormal, acEdit
DoCmd.SetWarnings True
DoCmd.Hourglass False
MsgBox ("Actions Completed!")
ENDIF
End If
Exit_cmdRunQuery__Click:
Exit Sub
Err_cmdRunQuery__Click:
MsgBox Err.Description
Resume Exit_cmdRunQuery__Click
End Sub
Please help, I’m very appreciated. Thanks