Type Mismatch

jojo86

Registered User.
Local time
Today, 22:54
Joined
Mar 7, 2007
Messages
80
This has been posted before, but I need to get an answer to it as it is for a tight deadline project at work.

I have a Add New Record button, and code in an OnClick() event, as shown below. The thing is, when I click the button, it doesn't execute the DoCmd.GoToRecord , , acNewRec line, and I can't see why.:confused:

Here is my code in the OnClick() event:

Code:
Private Sub cmdNewSite_Click()
On Error GoTo Err_cmdNewSite_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FRM_PRIMARY"
DoCmd.OpenForm stDocName, , , , stLinkCriteria
DoCmd.GoToRecord , , acNewRec
DoCmd.Close acForm, "FRM_MENU" 'This is to shut the Menu down when I
'click the button

Exit_cmdNewSite_Click:
Exit Sub

Err_cmdNewSite_Click:
MsgBox Err.Description
Resume Exit_cmdNewSite_Click

End Sub

I appreciate any help on this one, thanks
 
Your problem is probably because even though your stLinkCriteria is empty, you have it as the 5th argument instead of the 4th. Speaking of the 5th argument, why not just open the form in AddMode?
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd
 
Last edited:
Your problem is probably because even though your stLinkCriteria is empty, you have it as the 5th argument instead of the 4th. Speaking of the 5th argument, why not just open the form in AddMode?
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd

I tried that, but it then states this for some reason:

"You can't assign a value to this object
* The object may be a control on a read-only form
* The object may be on a form that is open in design view
* The value may be too large for this field"

I have also made the stLinkCriteria the 4th arguement, and the same error message pops up.
I can't see why this is happening...:confused:
 
JoJo,
Something else is going on. Can you post your db? Compact and Repair first and then zip it up. It needs to be <394KB in order to post. Remove any sensitive data first. If you can't post then PM me and I'll give you my email addy.
 
Correct me if I'm wrong, but if you are using stLinkCriteria in the criteria shouldn't you be assigning the criteria to it? It seems to me that you've declared the variable yet left it null.
 
Ruralguy: I have posted it up as two threads, but it hasn't been resolved in the fact that if I want to change some data on the first subform, the error message pops up. I have found, however, that if the fields in the main form are completed before entering data into the subform, the error message does not pop up. I took your advice/help for this btw, so thank you very much :)

Boblarson: In reply, I have copied this from another thread, assuming it would be right. I don't think it is doing any harm being null is it? If so, shall I just take it out?
 
I don't think it is doing any harm being null is it? If so, shall I just take it out?
AFAIK it does *no* harm to leave in the argument even though it is empty. Any chance to post your db?
 

Users who are viewing this thread

Back
Top Bottom