Type Mismatch

G

Guest

When I click on a command button with the following code, I get a Type
Mismatch Code. Although the error message shows "Type Mismatch" it opens the
form and lets me save any changes, etc. Can anyone think of a reason why it
would give me this error? I have checked that all the fields are the same
data type. Thanks.


Private Sub cmdbtnProgressNotes_Click()
On Error GoTo Err_cmdbtnProgressNotes_Click

Dim strLinkCriteria As String
Dim strDocName As String

strDocName = "subfrmToDoProgressNotes"
' If ToDoInstructionsID control is blank, display a message.
If IsNull(Me![ToDoInstructionsID]) Then
Me![ToDoProgressNotesID].SetFocus
Else
' Otherwise, open Product List form, showing products for current
supplier.
strDocName = "subfrmToDoProgressNotes"
strLinkCriteria = "[ToDoInstructionsID]=" & Me![ToDoInstructionsID]
DoCmd.OpenForm strDocName, , , strLinkCriteria
DoCmd.OpenForm strDocName, acFormAdd, , , strLinkCriteria
End If

Exit_cmdbtnProgressNotes_Click:
Exit Sub

Err_cmdbtnProgressNotes_Click:
MsgBox Err.Description
Resume Exit_cmdbtnProgressNotes_Click

End Sub
 
G

Guest

If the ToDoInstructionsID field type is string hen add a single quote to it

strLinkCriteria = "[ToDoInstructionsID]='" & Me![ToDoInstructionsID] & "'"

Also, this line, if you apen the form to add new record, you can remove the
criteria, and change the order

DoCmd.OpenForm strDocName, , , ,acFormAdd
 
G

Guest

DoCmd.OpenForm strDocName, , , strLinkCriteria
This line appears to be correct, assuming [ToDoInstructionsID] is a numeric
field.

DoCmd.OpenForm strDocName, acFormAdd, , , strLinkCriteria
This line is incorrect. First, acFormAdd is not a valid option for the View
argument. And, because you added this in without removing one of the
following commas, it throws strLinkCriteria out of position. It should be
the fourth argument, not the fifth. If you are, in fact, wanting to open the
form in add only data mode, it should follow the strLinkCriteria.
I think you want this
DoCmd.OpenForm strDocName, , , strLinkCriteria, acFormAdd
 
G

Guest

Ofer and Klatuu,

Thanks so much for your help. It works fine now!
--
S


Klatuu said:
DoCmd.OpenForm strDocName, , , strLinkCriteria
This line appears to be correct, assuming [ToDoInstructionsID] is a numeric
field.

DoCmd.OpenForm strDocName, acFormAdd, , , strLinkCriteria
This line is incorrect. First, acFormAdd is not a valid option for the View
argument. And, because you added this in without removing one of the
following commas, it throws strLinkCriteria out of position. It should be
the fourth argument, not the fifth. If you are, in fact, wanting to open the
form in add only data mode, it should follow the strLinkCriteria.
I think you want this
DoCmd.OpenForm strDocName, , , strLinkCriteria, acFormAdd
--
Dave Hargis, Microsoft Access MVP


Sharon said:
When I click on a command button with the following code, I get a Type
Mismatch Code. Although the error message shows "Type Mismatch" it opens the
form and lets me save any changes, etc. Can anyone think of a reason why it
would give me this error? I have checked that all the fields are the same
data type. Thanks.


Private Sub cmdbtnProgressNotes_Click()
On Error GoTo Err_cmdbtnProgressNotes_Click

Dim strLinkCriteria As String
Dim strDocName As String

strDocName = "subfrmToDoProgressNotes"
' If ToDoInstructionsID control is blank, display a message.
If IsNull(Me![ToDoInstructionsID]) Then
Me![ToDoProgressNotesID].SetFocus
Else
' Otherwise, open Product List form, showing products for current
supplier.
strDocName = "subfrmToDoProgressNotes"
strLinkCriteria = "[ToDoInstructionsID]=" & Me![ToDoInstructionsID]
DoCmd.OpenForm strDocName, , , strLinkCriteria
DoCmd.OpenForm strDocName, acFormAdd, , , strLinkCriteria
End If

Exit_cmdbtnProgressNotes_Click:
Exit Sub

Err_cmdbtnProgressNotes_Click:
MsgBox Err.Description
Resume Exit_cmdbtnProgressNotes_Click

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top