无法在Access vba

时间:2015-10-14 19:14:02

标签: ms-access access-vba

我正在开发一个Access DB,用于对我公司的业务联系人进行排序和跟踪。我们有一个名为“联系人资料”的表格,用户可以选择一个给定的联系人并查看他的所有信息:名字,姓氏,公司,职务,电子邮件地址等。

在个人资料中,用户可以使用“更新信息”按钮更新联系人的信息。

除了电子邮件地址外,每个字段都可以更新。例如,我可以将Google的程序员Joseph Smith改为GOOG的项目经理Joe Smith,没有任何问题。

但是,如果我尝试将joesmith@google.com更改为jsmith@google.com,则更改不会保存。代码发布在下面。有人可以看看,如果他们有任何建议,请告诉我?谢谢!

Private Sub Command61_Click()

Dim strFirstName As String
Dim strLastName As String
Dim strIndustry As String
Dim strCountry As String
Dim strState As String
Dim strCity As String
Dim strCompany As String
Dim strTitle As String
Dim strStatus As String
Dim strPhone As String
Dim strEmail As String
Dim strOwner As String
Dim DateNow As String

'Allow user to leave some fields blank. User must fill in certain fields.

Dim VisEnable

If IsNull(Me.txtFirstName) Then
    MsgBox ("Please add First Name for this Prospect")
    Me.txtFirstName.SetFocus
    Exit Sub
End If

If IsNull(Me.txtLastName) Then
    MsgBox ("Please add Last Name for this Prospect")
    Me.txtLastName.SetFocus
    Exit Sub
End If

If IsNull(Me.cboIndustry) Then
    Me.cboIndustry = ""
End If

If IsNull(Me.cboGeo) Then
    Me.cboGeo = ""
End If

If IsNull(Me.cboInfluence) Then
    Me.cboInfluence = ""
End If

If IsNull(Me.cboSchool) Then
    Me.cboSchool = ""
End If

If IsNull(Me.cboTier) Then
    Me.cboTier = ""
End If

If IsNull(Me.cboCompany) Then
    Me.cboCompany = ""
End If

If IsNull(Me.txtTitle) Then
    Me.txtTitle = ""
End If

If IsNull(Me.cboStatus) Then
    Me.cboStatus = ""
End If

If IsNull(Me.cboOwner) Then
    Me.cboOwner = ""
End If

If IsNull(Me.txtPhone) Then
    Me.txtPhone = ""
End If

If IsNull(Me.txtEmail) Then
    MsgBox ("Please add Email for this Prospect")
    Me.txtEmail.SetFocus
    Exit Sub
End If

If IsNull(Me.txtNotes) Then
    Me.txtNotes = ""
End If

If IsNull(Me.txtInitialProspectEmailSentDate) Then
Me.txtInitialProspectEmailSentDate = ""
End If

If IsNull(Me.txtNextTouchPoint) Then
Me.txtNextTouchPoint = ""
End If

strFirstName = Me.txtFirstName
strLastName = Me.txtLastName
strIndustry = Me.cboIndustry
strCompany = Me.cboCompany
strTitle = Me.txtTitle
strStatus = Me.cboStatus
strPhone = Me.txtPhone
strEmail = Me.txtEmail
strNotes = Me.txtNotes
strOwner = Me.cboOwner
dtEmailSent = Me.txtInitialProspectEmailSentDate
dtNextTouchPoint = Me.txtNextTouchPoint
strRegion = Me.cboGeo
strSoR = Me.cboTier
strInfluence = Me.cboInfluence
strClient = Me.ckClient
strCoworker = Me.ckCoworker
strSchool = Me.cboSchool

strSQL = "Update tblProspect Set FirstName = " & """" & strFirstName & """" & ",LastName = " & """" & strLastName & """" & ",Industry = " & """" & strIndustry & """" & "" & _
",Geography = " & """" & strRegion & """" & ",StrengthofRelationship = " & """" & strSoR & """" & ",School = " & """" & strSchool & """" & ",Company = " & """" & strCompany & """" & "" & _
",Title = " & """" & strTitle & """" & ",Status = " & """" & strStatus & """" & ", InfluenceLevel = " & """" & strInfluence & """" & ", FormerClient = " & strClient & ", FormerCoWorker = " & strCoworker & "" & _
",Email = " & """" & strEmail & """" & ",Phone = " & """" & strPhone & """" & ",ProspectOwner = " & """" & strOwner & """" & ",Notes = " & """" & strNotes & """" & ""


If dtNextTouchPoint <> "" Then
strSQL = strSQL & " ,NextTouchPoint = #" & dtNextTouchPoint & "#"
End If

If dtEmailSent <> "" Then
strSQL = strSQL & " ,LastEmailDate = #" & dtEmailSent & "#"
End If
strSQL = strSQL & " WHERE Email = " & """" & strEmail & """" & ""
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True


     Dim ctl As Control
    For Each ctl In Me.Controls
        Select Case ctl.ControlType
            Case acTextBox, acComboBox, acListBox, acCheckBox
                If ctl.ControlSource = "" Then
                    ctl.Value = Null
                End If
            Case Else
        End Select
    Next ctl


Me.Visible = False
DoCmd.OpenForm "frmProspectAdmin", acNormal, , , acFormEdit, acWindowNormal

DoCmd.RunCommand acCmdSaveRecord

Form_frmProspectProfile.Refresh

Form_frmProspectAdmin.Refresh

End Sub

1 个答案:

答案 0 :(得分:0)

它很可能是我想在Debug.Print中使用它,但它不会在联系人配置文件中保存这种方式。

Debug.Print strSQL
Update tblProspect Set FirstName = "Jon",LastName = "Snow",Industry = "Other",Geography = "",StrengthofRelationship = "",School = "",Company = "",Title = "",Status = "Dead", InfluenceLevel = "", FormerClient = 0, FormerCoWorker = 0,Email = "jsnow@winterfell",Phone = "",ProspectOwner = "",Notes = ""