Selasa, 03 September 2013

[MS_AccessPros] RE: writing a new record via the VBA

 

Wow! Yahoo really messed up your post. I had to copy it into an HTML editor to read it. 
Try turning off the filter before you do a Form Requery  which actually should be coded as Me.Requery.
So what I am proposing is this:
Me.FilterOn = False Me.Requery

--- In MS_Access_Professionals@yahoogroups.com, <ms_access_professionals@yahoogroups.com> wrote:

I have a continuous form that displays a set of records from my Animals table that displays a subset of animals based on search criteria set from unbound fields in the form header.  (It does this by manipulating the filter and turning it on)<br><br>I have another set of unbound fields in the header that is intended to set values for adding a journal record (in the Animal Journal table, related by Animal ID) for each of the animals listed in the continuous form.<br><br>I originally created a button to run a SQL statement with a DoCmd.RunSQL (statement) command.  It loops through the records in the continuous form, running the "Insert" The command does add the records to the database, but the form then locks up, so I cannot use the form to select another set of animals.<br><br>By "locking up", I mean that the Label_Preview that sets the filter does not appear to affect the form's results anymore, and the results in the form result show "#Name?" as if the form needs information to display the results <br><br>Is there something I should do to reset the form's filter?  Should I be using something besides a SQL command to add the records (like a acNewRec or something?)<br><br>(screenshot attached)<br><br>Relevant code:<br><br><div style="margin-left:40px;">Private Sub Form_Load()<br>Me.Combo_Population = "Current Animals"<br>Me.AJ_date = Date<br>Me.FilterOn = True<br>End Sub<br><br>Private Sub Label_Preview_Click()<br>' this is a text link that the user clicks on to preview the results of his subset of animals that will receive new journal entries<br><br>On Error GoTo Err_Label_Preview_Click<br><br>    Dim strWhere As String<br>    Dim IngLen As Long<br>    <br>    strWhere = ""<br>    prevDesc = ""<br></div><div>    <br><span style="font-style:italic;">(then a bunch of code that sets the strWhere value)<br><br></span><br><div style="margin-left:40px;">If IngLen <= 0 Then<br>        strWhere = ""<br>    Else<br>        strWhere = Left$(strWhere, IngLen)<br>        <br>        Me.Filter = strWhere<br>        Me.FilterOn = True<br>        <br>    End If<br>    <br><br>Exit_Label_Preview_Click:<br>    Exit Sub<br><br>Err_Label_Preview_Click:<br>    MsgBox Err.Description<br>    Resume Exit_Label_Preview_Click<br>    <br>End Sub<br><br>Private Sub AJ_Click()<br>' this is a button that adds a record to the Journal table based on each Animal record in the filtered form<br>On Error GoTo Err_AJ_Click<br><br>Dim RecordsChanged As Integer<br>Dim rsAnimals As DAO.Recordset<br>RecordsChanged = 0<br><br>strDesc = "Journal Entry: " & Me.AJ_date & ", " & Me.AJ_Type & ", " & Me.Note<br>Me.Session_Log = Me.Session_Log & vbCrLf & strDesc & vbCrLf & "Added to "<br><br><br>Set rsAnimals = Me.Recordset<br>rsAnimals.MoveFirst<br><br>Do While Not rsAnimals.EOF<br>    <br>    If Me.Journal_Toggle = True Then<br>  <br>    Dim statement As String<br>    Dim AJDate As Date<br>    <br>    statement = "Insert into [Animal Journal] ([AJ Date], [Animal ID], [AJ Type], [Note], [Timestamp]) Values ('" & Me.AJ_date & "', '" & Trim(Me.Animal_ID) & "', '" & Me.AJ_Type & "', '" & Me.Note & "', '" & Date & "');"<br>    RecordsChanged = RecordsChanged + 1<br>    DoCmd.RunSQL (statement)<br>    Me.Session_Log = Me.Session_Log & vbCrLf & "     " & Me.House_Name<br>    <br>    End If<br>    <br>    rsAnimals.MoveNext<br>Loop<br><br>rsAnimals.Close<br><br><br>Exit_AJ_Click:<br>    Exit Sub<br><br>Err_AJ_Click:<br>    MsgBox Err.Description<br>    Resume Exit_AJ_Click<br>    <br>Form.Requery<br>    <br>End Sub<br><br><br></div></div>

[Non-text portions of this message have been removed]

__._,_.___
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (2)
Recent Activity:
.

__,_._,___

Tidak ada komentar:

Posting Komentar