tupac1979
asked on
I am recieving a duplicate declaration in current scope error message
I am developingr an employee training database for the company and with this code I want the user to check in a checkbox if the user has taken a class or not. If the user has not taken the class then the checkbox should be empty and the user will then select a class and the class will go into my table. If the user does select the checkbox then they will have enter the class and a date the class was taken. One of first problems is that if the user does not check the checkbox and does not enter in a date then an error message comes up. If the user does select the checkbox and enter in a date then the code works fine. Does anyone have any suggestions as to how I can enter the information in the table without the user having to enter in a date and disable the date field if the checkbox is not selected ?
Private Sub cmdTrain_Click()
Dim ClassDate As Date
Dim empID As Integer
Dim occid As Integer
Dim req As Variant
Dim classtaken As Integer
Dim strSQL As String
Dim str1SQL As String
ClassDate = Me.Date
occid = Me.OccupationID
req = cboClass.Column(0)
classtaken = -1
empID = cboemp.Column(0)
If Me.classcheck.Value = True Then
Me.Date.SetFocus
Else
Me.Date.Enabled = False
End If
If Not IsDate(Me.Date.Value) Then
MsgBox "Please enter a valid date"
Exit Sub
End If
If Not IsNull(cboClass.Column(0) And Me.Date) Then
strSQL = "INSERT INTO Employee_Train (FileID, OccupationID, ClassID, ClassTaken, DateTaken) VALUES (" & empID & ", " & occid & ", " & req & ", " & classtaken & ", #" & ClassDate & "#)"
CurrentDb.Execute (strSQL)
ElseIf IsNull(Me.Date) Then
str1SQL = "INSERT INTO Employee_Train(FileID, OccupationID, ClassID, ClassTaken, DateTaken) VALUES (" & empID & ", " & occid & ", " & req & ", " & classtaken & ")"
CurrentDb.Execute (str1SQL)
End If
End Sub
Private Sub cmdTrain_Click()
Dim ClassDate As Date
Dim empID As Integer
Dim occid As Integer
Dim req As Variant
Dim classtaken As Integer
Dim strSQL As String
Dim str1SQL As String
ClassDate = Me.Date
occid = Me.OccupationID
req = cboClass.Column(0)
classtaken = -1
empID = cboemp.Column(0)
If Me.classcheck.Value = True Then
Me.Date.SetFocus
Else
Me.Date.Enabled = False
End If
If Not IsDate(Me.Date.Value) Then
MsgBox "Please enter a valid date"
Exit Sub
End If
If Not IsNull(cboClass.Column(0) And Me.Date) Then
strSQL = "INSERT INTO Employee_Train (FileID, OccupationID, ClassID, ClassTaken, DateTaken) VALUES (" & empID & ", " & occid & ", " & req & ", " & classtaken & ", #" & ClassDate & "#)"
CurrentDb.Execute (strSQL)
ElseIf IsNull(Me.Date) Then
str1SQL = "INSERT INTO Employee_Train(FileID, OccupationID, ClassID, ClassTaken, DateTaken) VALUES (" & empID & ", " & occid & ", " & req & ", " & classtaken & ")"
CurrentDb.Execute (str1SQL)
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks I have changed the name on my form from date to cDate but I donot want a date to go in there if the user does not select the checkbox. do you think there is a way for that to happen or do I have to enter in a date variable for the SQL statement
if you do not want a date to be inserted if the user does not select the checkbox, what do you want to have happen in that case? I think I ammissing something about what it is you want to have happen. Can you describe, in words (forgetting about the programminig for the moment) EXACTLY what is supposed to happen with your form?
AW
AW
ASKER
ClassDate = Me.Date
this only occurs when I do not input a date on my form