I have a tenant details form that has a field called TenantID, I also have a Lease table that also has a TenantID field, what I want to do is click the lease button, check to see if the lease already exists, if it does open the lease form to that record. If not then open the lease form to a New record so the user can enter all the information for that lease.
I am trying to use the below code but am having a little trouble understanding how it all works. What needs to be declared, what doesnt
HTML Code:Private Sub btnLease_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLease.Click Dim fm2 As New LeaseDetails Dim str As String Dim cmd As String Using conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.12.0;Data Source=" & Application.StartupPath & "\Tenant Tracker 2011_be.accdb;Persist Security Info=False") Using cmd As SqlClient.SqlCommand = conn.CreateCommand() conn.Open() str = "SELECT * FROM Lease WHERE ContactID =" & ContactID.Text & "" cmd = New OleDbCommand(str, conn) dr = cmd.ExecuteReader() If Not dr.HasRows Then AddNew = True Else fm2.idToOpen = Me.ContactID.Text End If End Using End Using fm2.Show() End Sub Thanks LB




Reply With Quote