Adding record to a table from data entry in another unbound form
Posted on 2013-05-31
Someone helped me a while back with an issue where I was trying to add a record to an unbound table from a field data entry in a form. Here's my code but it's broken and I can't figure out why.
When I try to close the form I get an error..."Too few parameters. Expected 1"
Here's my code...
Private Sub Form_Close()
'Code to create a new record in tblExample with values from combobox if that combination of data doesn't already exist in the table
If Me.cboProjectName > "" Then
If DCount("*", "tblProjectNames", "ProjectName = " & Chr(34) & Me.cboProjectName & Chr(34)) > 0 Then
'MsgBox "This record already exists."
MsgBox "This appears to be a new record which does not already exist in the program. A new record is being created."
Dim RS As DAO.Recordset
Set RS = CurrentDb.OpenRecordset("tblProjectNames")
RS!ProjectName = Me.cboProjectName
'End of code to create a new record in separate table with values from combobox if that record doesn't already exist in the table