R
Richard Hollenbeck
I have DAO 3.6 Object referenced. What else could I be missing? I can't
figure out why I'm getting a type mismatch error. I've tried a bunch of
things I modified this code from VBA Help. Here's the code:
Option Compare Database
Option Explicit
Private Sub cmdAddIngredient_Click()
On Error GoTo Err_cmdAddIngredient_Click
Dim StrSQL As String, NewIngred As String
Dim dbRecipes As DAO.Database
Dim rsIngredients As DAO.Recordset
Set dbRecipes = CurrentDb
Set rsIngredients = dbRecipes.OpenRecordset("tblIngredients",
dbOpenDynaset)
rsIngredients.MoveLast
'Get data from the user.
NewIngred = InputBox("Enter a new ingredient:")
If NewIngred <> "" Then
AddName rsIngredients, NewIngred
End If
Exit_cmdAddIngredient_Click:
Exit Sub
Err_cmdAddIngredient_Click:
MsgBox Err.Description
Resume Exit_cmdAddIngredient_Click
End Sub
Private Function AddName(rstTemp As Recordset, strName As String)
' Adds a new record to a recordset using the data passes
' by the calling procedure. The new record is then made
' the current record
With rstTemp
.AddNew
!IngredientName = strName 'IngredientName is a text field in
tblIngredients
.Update
End With
End Function
figure out why I'm getting a type mismatch error. I've tried a bunch of
things I modified this code from VBA Help. Here's the code:
Option Compare Database
Option Explicit
Private Sub cmdAddIngredient_Click()
On Error GoTo Err_cmdAddIngredient_Click
Dim StrSQL As String, NewIngred As String
Dim dbRecipes As DAO.Database
Dim rsIngredients As DAO.Recordset
Set dbRecipes = CurrentDb
Set rsIngredients = dbRecipes.OpenRecordset("tblIngredients",
dbOpenDynaset)
rsIngredients.MoveLast
'Get data from the user.
NewIngred = InputBox("Enter a new ingredient:")
If NewIngred <> "" Then
AddName rsIngredients, NewIngred
End If
Exit_cmdAddIngredient_Click:
Exit Sub
Err_cmdAddIngredient_Click:
MsgBox Err.Description
Resume Exit_cmdAddIngredient_Click
End Sub
Private Function AddName(rstTemp As Recordset, strName As String)
' Adds a new record to a recordset using the data passes
' by the calling procedure. The new record is then made
' the current record
With rstTemp
.AddNew
!IngredientName = strName 'IngredientName is a text field in
tblIngredients
.Update
End With
End Function