ganesh_6663
New Member
- Joined
- Jul 15, 2021
- Messages
- 33
- Office Version
- 2016
- Platform
- Windows
Hi Team,
Below code need to add condition If AREA ID not found in database need popup msg showing "AREA ID not preset in Database2.accdb"
Below code need to add condition If AREA ID not found in database need popup msg showing "AREA ID not preset in Database2.accdb"
VBA Code:
Private Sub CommandButton5_Click()
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim qry As String, i As Integer
Dim n As Long
If Me.Reg1.Value = "" Then
MsgBox "Please enter the AREA ID", vbCritical
Exit Sub
End If
qry = "Select * from DATABASE123 where Data='" & Me.Reg1.Value & "'"
cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.Path & "\Database2.accdb"
rst.Open qry, cnn, adOpenKeyset, adLockOptimistic
Reg1 = Me.Reg1.Value
Me.Reg2.Value = rst.Fields("a1").Value
Me.Reg3.Value = rst.Fields("a2").Value
Me.TextBox6.Value = rst.Fields("a3").Value
rst.Close
cnn.Close
End Sub