irunergoiam
Registered User.
- Local time
- Yesterday, 19:32
- Joined
- May 30, 2009
- Messages
- 76
I’m kind of stuck on my Dim statements and was hoping you might be able to give me a little nudge.
The first thing I’m trying to do is see if a record (by employee ID) already exists, if a record does exist, I want the “Save” button to Update the related record in the table with the unbound fields from the form. The problem I’m having is that I’m already dimming strCriteria As String and dimming strSQL as String to see if the record exists (see Dim statements in red with *). When it determines that it exists, I am not able to get the DoCmd.RunSQL strSQL command to run as I’ve told it to Dim again (see Dim statements in red with #).
I know this isn’t correct, but can’t get it to run when I remove the Dim statements for the DoCmd.RunSQL strSQL command and am hoping that someone might be able to give me a nudge on this one as I’m pretty new to something this complex.
Thanks…
Private Sub Save_Click()
*Dim varExists As Variant
*Dim strCriteria As String
*Dim strSQL As String
strCriteria = "[Data File].Employee = '" & Me.cmbCandidate.Column(7) & "'"
varExists = DLookup("Employee", "Data File", strCriteria)
If Not IsNull(varExists) Then
response = MsgBox(" An Attestation record already exists for this employee. Update employee's attestation record?", vbYesNo, "EEID Attestation On File")
If response = vbYes Then
DoCmd.SetWarnings False
#Dim strSQL As String
#Dim strCriteria As String
strSQL = "UPDATE [Data File] SET [Data File].[Yrs of Experience] = " & unbExperience & ", [Data File].[As of Date] = #" & unbAsOfDate & "#, [Data File].[Comments] = '" & unbComments & "', [Data File].[Full Name] = '" & cmbCandidate & "', [Data File].[EnteredBy] = '" & unbEnteredBy & "', [Data File].[EnteredDate] = #" & unbEnteredDate & "#, [Data File].[EnteredTime] = #" & unbEnteredTime & "#, [Data File].[DateTime] = Now(), [Data File].[First Name] = '" & unbFirstName & "', [Data File].[Last Name] = '" & unbLastName & "'"
strSQL = strSQL & "WHERE((([Data File].Employee) = [Forms]![AttestationForm]![unbKenexaEEID]);"
DoCmd.RunSQL strSQL
The first thing I’m trying to do is see if a record (by employee ID) already exists, if a record does exist, I want the “Save” button to Update the related record in the table with the unbound fields from the form. The problem I’m having is that I’m already dimming strCriteria As String and dimming strSQL as String to see if the record exists (see Dim statements in red with *). When it determines that it exists, I am not able to get the DoCmd.RunSQL strSQL command to run as I’ve told it to Dim again (see Dim statements in red with #).
I know this isn’t correct, but can’t get it to run when I remove the Dim statements for the DoCmd.RunSQL strSQL command and am hoping that someone might be able to give me a nudge on this one as I’m pretty new to something this complex.
Thanks…
Private Sub Save_Click()
*Dim varExists As Variant
*Dim strCriteria As String
*Dim strSQL As String
strCriteria = "[Data File].Employee = '" & Me.cmbCandidate.Column(7) & "'"
varExists = DLookup("Employee", "Data File", strCriteria)
If Not IsNull(varExists) Then
response = MsgBox(" An Attestation record already exists for this employee. Update employee's attestation record?", vbYesNo, "EEID Attestation On File")
If response = vbYes Then
DoCmd.SetWarnings False
#Dim strSQL As String
#Dim strCriteria As String
strSQL = "UPDATE [Data File] SET [Data File].[Yrs of Experience] = " & unbExperience & ", [Data File].[As of Date] = #" & unbAsOfDate & "#, [Data File].[Comments] = '" & unbComments & "', [Data File].[Full Name] = '" & cmbCandidate & "', [Data File].[EnteredBy] = '" & unbEnteredBy & "', [Data File].[EnteredDate] = #" & unbEnteredDate & "#, [Data File].[EnteredTime] = #" & unbEnteredTime & "#, [Data File].[DateTime] = Now(), [Data File].[First Name] = '" & unbFirstName & "', [Data File].[Last Name] = '" & unbLastName & "'"
strSQL = strSQL & "WHERE((([Data File].Employee) = [Forms]![AttestationForm]![unbKenexaEEID]);"
DoCmd.RunSQL strSQL