Ms access 无法在Access vba中更新窗体上的文本框
我正在开发一个Access DB,它可以对我公司的业务联系人进行分类和跟踪。我们有一个名为Contact Profile的表单,用户可以通过该表单选择给定联系人并查看其所有信息:姓名、姓氏、公司、职务、电子邮件地址等 在个人资料中,用户可以使用“更新信息”按钮更新联系人信息 除电子邮件地址外,每个字段都会正常更新。例如,我可以把谷歌的程序员约瑟夫·史密斯换成谷歌的程序经理乔·史密斯,没有任何问题 但如果我试图改变joesmith@google.com到jsmith@google.com,则更改不会保存。代码发布在下面。有人能看一看并告诉我他们有什么建议吗?谢谢Ms access 无法在Access vba中更新窗体上的文本框,ms-access,vba,Ms Access,Vba,我正在开发一个Access DB,它可以对我公司的业务联系人进行分类和跟踪。我们有一个名为Contact Profile的表单,用户可以通过该表单选择给定联系人并查看其所有信息:姓名、姓氏、公司、职务、电子邮件地址等 在个人资料中,用户可以使用“更新信息”按钮更新联系人信息 除电子邮件地址外,每个字段都会正常更新。例如,我可以把谷歌的程序员约瑟夫·史密斯换成谷歌的程序经理乔·史密斯,没有任何问题 但如果我试图改变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
结果很可能是我希望它在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 = ""
有东西被水淹了。您的VBA代码包括strSQL=strSQL&WHERE-Email=&&strEmail&&。。。但此UPDATE语句中没有WHERE子句。Debug.Print strSQL UPDATE tblProspect Set FirstName=Jon,LastName=Snow,行业=Other,地理=,STRENGHTHOFRelationship=,学校=,公司=,标题=,状态=Dead,影响级别=,FormerClient=0,FormerWorker=0,电子邮件=jsnow@winterfell,电话=,浏览者=,备注=其中电子邮件=jsnow@winterfell^^WHERE子句就是这样