TurboDieselOne
Registered User.
- Local time
- Today, 12:17
- Joined
- Jan 16, 2003
- Messages
- 39
I need to Update The trelNametoAddress with new Name but Keep the Address I notice at the Bottom of the Code for Proc Sub cmdAddAddress there is some code that Creates a new Address related to the Company but I wish to Create a new Name related to the Address an update trelNametoAddress.
Private Sub cmdAddCompany_Click()
Dim x As Integer
x = MsgBox("Do You wish to Add this Company to the Database?", vbYesNo)
If x = vbYes Then
Dim strSql As String
Dim cmd As ADODB.Command
Set cmd = New ADODB.Command
strSql = "INSERT INTO tblNames ([Classification],[Name1],[CompanyWorkingFor],[Name2],[Name3],[Name4],[Keyword])" & _
" VALUES ('" & Me!cboClassification & "', '" & Me!cboName1 & "', '" & Me!cboCompanyWorkingFor & "', '" & Me!txtName2 & "', '" & Me!txtName3 & "', '" & Me!txtName4 & "', '" & Me!cboKeyword & "')"
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandText = strSql
cmd.Execute
Else
DoCmd.CancelEvent
End If
End Sub
Private Sub cmdAddAddress_Click()
Dim x As Integer
x = MsgBox("Do You wish to Add this Record to the Database?", vbYesNo)
If x = vbYes Then
Dim strSql As String
Dim cmd As ADODB.Command
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
Set cmd = New ADODB.Command
strSql = "INSERT INTO tblAddress (Name,Address1, Address2, Address3, Address4,City,Postcode,County,Country)" & _
" VALUES ('" & Me.cboAddressName1 & "', '" & Me.txtAddress1 & "', '" & Me.txtAddress2 & "', '" & Me.txtAddress3 & "', '" & Me.txtAddress4 & "', '" & Me.cboCity & "', '" & Me.cboPostcode & "', '" & Me.cboCounty & "', '" & Me.cboCountry & "')"
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandText = strSql
cmd.Execute
rst.Open "tblAddress", CurrentProject.Connection, adOpenDynamic
rst.MoveLast
strSql = "INSERT INTO trelNameToAddress (NameId, AddressId)" & _
" VALUES ('" & Me.intNamesID & "', '" & rst!AddressID & "')"
cmd.CommandText = strSql
cmd.Execute
Else
DoCmd.CancelEvent
End If
Me.Form.Requery
End Sub
Private Sub cmdAddCompany_Click()
Dim x As Integer
x = MsgBox("Do You wish to Add this Company to the Database?", vbYesNo)
If x = vbYes Then
Dim strSql As String
Dim cmd As ADODB.Command
Set cmd = New ADODB.Command
strSql = "INSERT INTO tblNames ([Classification],[Name1],[CompanyWorkingFor],[Name2],[Name3],[Name4],[Keyword])" & _
" VALUES ('" & Me!cboClassification & "', '" & Me!cboName1 & "', '" & Me!cboCompanyWorkingFor & "', '" & Me!txtName2 & "', '" & Me!txtName3 & "', '" & Me!txtName4 & "', '" & Me!cboKeyword & "')"
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandText = strSql
cmd.Execute
Else
DoCmd.CancelEvent
End If
End Sub
Private Sub cmdAddAddress_Click()
Dim x As Integer
x = MsgBox("Do You wish to Add this Record to the Database?", vbYesNo)
If x = vbYes Then
Dim strSql As String
Dim cmd As ADODB.Command
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
Set cmd = New ADODB.Command
strSql = "INSERT INTO tblAddress (Name,Address1, Address2, Address3, Address4,City,Postcode,County,Country)" & _
" VALUES ('" & Me.cboAddressName1 & "', '" & Me.txtAddress1 & "', '" & Me.txtAddress2 & "', '" & Me.txtAddress3 & "', '" & Me.txtAddress4 & "', '" & Me.cboCity & "', '" & Me.cboPostcode & "', '" & Me.cboCounty & "', '" & Me.cboCountry & "')"
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandText = strSql
cmd.Execute
rst.Open "tblAddress", CurrentProject.Connection, adOpenDynamic
rst.MoveLast
strSql = "INSERT INTO trelNameToAddress (NameId, AddressId)" & _
" VALUES ('" & Me.intNamesID & "', '" & rst!AddressID & "')"
cmd.CommandText = strSql
cmd.Execute
Else
DoCmd.CancelEvent
End If
Me.Form.Requery
End Sub