'Expected Variable or Function'

TheStriker

Registered User.
Local time
Today, 15:29
Joined
Jan 5, 2004
Messages
17
Hello,

Error: Expected Variable or Function

I got the error message while running the following code:

*************************************************
Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click
Dim rs As Recordset

Set rs = Me.RecordsetClone

'Check user's permissions

If Forms![New]![ctrlAdmin].Value = False Then
MsgBox "You are not authorized to perform this action. Please log in as Administrator and try your request again", vbExclamation + vbOKOnly, "Unauthorized User"

Else

rs.AddNew("nSiteID") = Forms![New]![nSiteID]
rs.Update
rs.Fields("sContactName").Value = sContactName
rs.Fields("sPhone").Value = sPhone
rs.Fields("sAltPhone").Value = sAltPhone
rs.Fields("sCellPhone").Value = sCellPhone
rs.Fields("sPager").Value = sPager
'-------------------------------------------------
Forms![New]![POC subform]![POCList].Requery
DoCmd.Close acForm, "POCUpdate", acSaveYes

End If
****************************************************

As you could see, I am trying to add a new record to the form's underlying query. I am a novice at VBA so any help/suggestions would be appreciated.

Thanks in advance.
 
You can't add to a recordsetclone; it's just a copy of the form's underlying recordsource.

and


Code:
rs.AddNew("nSiteID") = Forms![New]![nSiteID]
rs.Update
rs.Fields("sContactName").Value = sContactName
rs.Fields("sPhone").Value = sPhone
rs.Fields("sAltPhone").Value = sAltPhone
rs.Fields("sCellPhone").Value = sCellPhone
rs.Fields("sPager").Value = sPager

is wrong

Code:
rs.AddNew("nSiteID") = Forms![New]![nSiteID]

rs.Fields("sContactName").Value = sContactName
rs.Fields("sPhone").Value = sPhone
rs.Fields("sAltPhone").Value = sAltPhone
rs.Fields("sCellPhone").Value = sCellPhone
rs.Fields("sPager").Value = sPager
rs.Update


ir right
 

Users who are viewing this thread

Back
Top Bottom