Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / June 2008

Tip: Looking for answers? Try searching our database.

when to refresh form data

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
gymphil - 23 Jun 2008 17:00 GMT
I am using a second form to enter new data, when I return back to the main
form I can only auto fill the productID detail, all the other data entered in
the 'newpart' form is not visible on the main form, Don't know how and where
to refresh the form data, can anyone assist? thankyou

Phil

Private Sub Combo14_AfterUpdate()

        Set rs = Me.Recordset.Clone
        rs.FindFirst "[productID] = '" & Me![Combo14] & "'"
        Me.Bookmark = rs.Bookmark
   
End Sub

Private Sub Combo14_NotInList(NewData As String, Response As Integer)

        Dim Result
        Dim Msg As String
        Dim CR As String: CR = Chr$(13)
        If NewData = "" Then Exit Sub
        Msg = "'" & NewData & "' is not in the list." & CR & CR
        Msg = Msg & "Do you want to add it?"
        If MsgBox(Msg, 32 + 4) = 6 Then
           DoCmd.OpenForm "newpart", , , , acAdd, acDialog, NewData
        End If
        Result = DLookup("[productID]", "products", _
                 "[productID]=""" & NewData & """")
        If IsNull(Result) Then
           Response = DATA_ERRCONTINUE
           MsgBox "Please try again!"
        Else
           Response = DATA_ERRADDED
        End If

     End Sub
Klatuu - 23 Jun 2008 17:35 GMT
Since you are adding the record using a different form, you current form
doesn't know about it yet.  You should requery your form in the Not In List
event after the record has been added in the add record form.  Then rather
than a DLookup, use the FindFirst method on the form's recordsetclone to
navigate to the newly added record.  Here is a modification of your current
code:

Private Sub Combo14_NotInList(NewData As String, Response As Integer)
Dim Msg As String

   If NewData = "" Then
       Exit Sub
   End If

   If MsgBox(NewData & "' is not in the list." & vbNewLine & vbNewLine & _
           "Do you want to add it?", vbQuestion + vbYesNo) = vbYes Then
       DoCmd.OpenForm "newpart", , , , acAdd, acDialog, NewData
       Me.Combo14.Undo
       DoCmd.OpenForm "newpart", , , , acAdd, acDialog, NewData
       Response = acDataErrAdded
       Me.Requery
       With Me.RecordsetClone
           .FindFirst "[ProductID] = """ & NewData & """"
           If Not .NoMatch Then
               Me.Bookmark = .Bookmark
           End If
       End With
   Else
       Me.Combo14.Undo
       Response = acDataErrContinue
    End If

End Sub

Notice I used the constants vbQuestion, vbYesNo, etc rather than their
values.  It makes the code much easier to read.  Also, no need to Dim a
variable for a line feed. there are at least two different intrinsic
constants that do that.  I prefer vbNewLine, because its purpose is obvious
to the reader.
Signature

Dave Hargis, Microsoft Access MVP

> I am using a second form to enter new data, when I return back to the main
> form I can only auto fill the productID detail, all the other data entered in
[quoted text clipped - 32 lines]
>
>       End Sub
gymphil - 24 Jun 2008 10:04 GMT
Dave,

Many thanks for that, I have changed the code and it works great. I would
have liked to use the same form to create new records but got into all sorts
of bother when using me.combo14 = me.productID on the forms on current event.

Thanks again Dave

Phil

> Since you are adding the record using a different form, you current form
> doesn't know about it yet.  You should requery your form in the Not In List
[quoted text clipped - 72 lines]
> >
> >       End Sub
Klatuu - 24 Jun 2008 15:42 GMT
Why do you need to do that?
Combo14 is not a bound control, is it?
Signature

Dave Hargis, Microsoft Access MVP

> Dave,
>
[quoted text clipped - 82 lines]
> > >
> > >       End Sub
gymphil - 26 Jun 2008 16:22 GMT
Dave,

No that's correct, combo14 is not bound, that was partly the problem. When
scrolling through the records on the form, the contents of the combobox
didn't change, this was misleading and the advice provided was to use
me.combo14 = me.productID, this kept the combobox in sync with the record
that appeared on the screen. But for some reason this created a conflict when
I tried to use the same form to add records.

Phil

> Why do you need to do that?
> Combo14 is not a bound control, is it?
[quoted text clipped - 85 lines]
> > > >
> > > >       End Sub
Klatuu - 26 Jun 2008 16:25 GMT
Okay, that makes sense.  My preference is to set it to Null so nothing shows
in it:
me.combo14 = Null
Signature

Dave Hargis, Microsoft Access MVP

> Dave,
>
[quoted text clipped - 96 lines]
> > > > >
> > > > >       End Sub
gymphil - 27 Jun 2008 09:40 GMT
I have got to keep the contents of the combo box visible otherwise I will not
know what record the fields on the form relate to!

Phil

> Okay, that makes sense.  My preference is to set it to Null so nothing shows
> in it:
[quoted text clipped - 100 lines]
> > > > > >
> > > > > >       End Sub
Klatuu - 27 Jun 2008 14:52 GMT
Use a bound text box to show the value rather than the combo.  To reduce
confusion, I use a bound text box and put my unbound search combo in the form
header.
Signature

Dave Hargis, Microsoft Access MVP

> I have got to keep the contents of the combo box visible otherwise I will not
> know what record the fields on the form relate to!
[quoted text clipped - 105 lines]
> > > > > > >
> > > > > > >       End Sub
gymphil - 30 Jun 2008 10:41 GMT
Dave,

I hadn't thought of doing it that way.

I would much rather use the same form for entering new records but could you
please tell me what changes I would need to make to the coding, I know I do
not need to open the new form but not sure about the rest of it.

Many thanks

Phil

> Use a bound text box to show the value rather than the combo.  To reduce
> confusion, I use a bound text box and put my unbound search combo in the form
[quoted text clipped - 109 lines]
> > > > > > > >
> > > > > > > >       End Sub
Klatuu - 30 Jun 2008 14:44 GMT
Just use the After Update event of the comb box to load the selected value
into the text box.
Signature

Dave Hargis, Microsoft Access MVP

> Dave,
>
[quoted text clipped - 121 lines]
> > > > > > > > >
> > > > > > > > >       End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.