runtime error 2118

Derek

Registered User.
Local time
Yesterday, 23:25
Joined
May 4, 2010
Messages
234
Hi Guys The runtime error "You Must Save Current Field before you run Requery" error message . ANy help will be much appreciated.
Code:
 Private Sub cmdSave_Click()
'Me.txtHidden.SetFocus
Dim rs As Recordset
 
If ValidateForm = False Then Exit Sub
 Set rs = CurrentDb.OpenRecordset("SELECT * FROM tbl_Mas_DocLog WHERE DocCode = '" & Me.txtCode & "'")
rs.Edit
rs!DocCode = Me.txtCode
rs!Owner = Me.cboOwner
rs!VersionID = Me.txtVersion
rs!Date_SignedOff = Me.txtDateSignedOff
rs!Date_Live = Me.txtDateLive
rs!Date_Expired = Me.txtDateExpires
rs!Date_Withdrawn = Null
rs!DocName = Me.txtDocName
rs!AreaID = Me.cboArea
rs!FileTypeID = Me.cboType
rs!Date_Withdrawn = Me.txtDateWithdrawn
rs!Comment = Me.txtComment
rs.Update
rs.Close
Set rs = Nothing
 Set rs = CurrentDb.OpenRecordset("tbl_Ref_DocLogHistory")
rs.AddNew
rs!DocCode = Me.txtCode
rs!Owner = Me.cboOwner
rs!VersionID = Me.txtVersion
rs!Date_SignedOff = Me.txtDateSignedOff
rs!Date_Live = Me.txtDateLive
rs!Date_Expired = Me.txtDateExpires
rs!Date_Withdrawn = Null
rs!DocName = Me.txtDocName
rs!AreaID = Me.cboArea
rs!FileTypeID = Me.cboType
rs!CreatedDate = Date
rs!CreatedTime = Time()
rs!CreatedBy = GetUserName()
 rs.Update
rs.Close
Set rs = Nothing
[COLOR=red]Forms!frm_Function_T!lstDue.Requery
 Forms!frm_Function_T!lstOverDue.Requery
[/COLOR]ClearDown

 DoCmd.Close
 End Sub
 
Is your form bound? If so, why are you running a recordset update for the record it's bound to?
 
No its not bound.
 
Its unbound form that's why the code updates the records. Not sure why this error message is coming up?
 
Is frm_Function_T the name of the form you're in?
If yes, then try:
Code:
Me.lstDue.Requery 
Me.lstOverDue.Requery
 
No I am not in this form but in a form upon this. That's why I have used this:

Code:
 [COLOR=#ff0000]Forms!frm_Function_T!lstDue.Requery
 Forms!frm_Function_T!lstOverDue.Requery[/COLOR]
 [COLOR=#ff0000]
[/COLOR]
 
No I am not in this form but in a form upon this.
What does that mean? A main form?
Try the below:
Code:
If Forms!frm_Function_T.Dirty then 
  Forms!frm_Function_T.Dirty = False
End if
[COLOR=red][COLOR=red][COLOR=red][COLOR=Black]Forms!frm_Function_T!lstDue.Requery
Forms!frm_Function_T!lstOverDue.Requery[/COLOR] [/COLOR][/COLOR] [/COLOR]
 
Yes frm_Function_T is the main form. I am writing the code on the Edit form. I tried this thing as well but still getting the same error message:
Code:
 If Forms!frm_Function_T.Dirty then 
  Forms!frm_Function_T.Dirty = False
End if
 
Post a stripped down version of your database with some sample data.
 
create a breakpoint on that sub. note which line produces the error.
 
The following line produces error:
Code:
 Forms!frm_Function_T!lstDue.Requery
 
ANy idea anyone why I am getting error message in that line?
 
I changed that line to the following and not getting any error now but it doesn't refresh the listbox named "lstDue"

Code:
 Forms("frm_Function_T").Controls("lstDue").Requery
 
Also In the form "Frm_Function_T", the listbox "lstDue" has a rowsource property which is set to as follows:

Code:
SELECT tbl_Mas_DocLog.DocCode, tbl_Mas_DocLog.DocName AS Name, tbl_Mas_DocLog.Date_Expired AS Review
FROM tbl_Mas_DocLog
WHERE (((tbl_Mas_DocLog.Date_Expired)<Date()) AND ((tbl_Mas_DocLog.Date_Withdrawn) Is Null));
 
JHB, because of security restrictions in the company, I am not able to send database attachment.
 
The only problem I am getting is to Refresh listbox on MainForm from the Editform(which is on the top of MainForm)
 
Maybe re-inserting the RowSource of the listbox will fix it:

Forms("frm_Function_T")("lstDue").RowSource = _
"SELECT tbl_Mas_DocLog.DocCode, tbl_Mas_DocLog.DocName AS Name, tbl_Mas_DocLog.Date_Expired AS Review
FROM tbl_Mas_DocLog
WHERE (((tbl_Mas_DocLog.Date_Expired)<Date()) AND ((tbl_Mas_DocLog.Date_Withdrawn) Is Null));"
 
If a form is unbound, there is nothing to requery. If a control is unbound, there is nothing to requery.

Therefore, in order for you to even contemplate a requery, something MUST be bound. What is it?
 

Users who are viewing this thread

Back
Top Bottom