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 / October 2007

Tip: Looking for answers? Try searching our database.

Regarding Forms and Forms representing Related Table Data

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
magmike - 30 Oct 2007 05:44 GMT
I have a main form (Contacts) which has many related tables. For this
message we will use the related table "Letters" which stores records
representing different letters and literature sent to a contact.

When a user on the Contact form, presses the "Letters" button, they
will see the Letter records related to the contact currently
possessing the contents of the Contact form. With navigation buttons
in place, the user can browse through all the correspondence sent to
the contact in question. However, when pressed, the New Records button
(Titled SendLetter) starts an altogether new record without the
contact id in place, requiring the user to purposely include the
information on the company in the new record. The goal, is that the
information on the contact the new letter will be related to, is
already filled in.

How can I do this?

thanks in advance!
NevilleT - 30 Oct 2007 07:43 GMT
Is the letter form a different form to the client form, and is the client
form still open when the letter form is open?  If so you can use the default
value of the letter client screen to display the existing client.  It is best
to use the build function to ensure no typos.  Go to the field (e.g. Client
Name) on the letter form, Click the data tab, go down to default and right
click.  Select Build and find the value you want from the other open form.

> I have a main form (Contacts) which has many related tables. For this
> message we will use the related table "Letters" which stores records
[quoted text clipped - 14 lines]
>
> thanks in advance!
magmike - 30 Oct 2007 19:19 GMT
On Oct 30, 1:43 am, NevilleT <Nevil...@discussions.microsoft.com>
wrote:
> Is the letter form a different form to the client form, and is the client
> form still open when the letter form is open?  If so you can use the default
[quoted text clipped - 23 lines]
>
> - Show quoted text -

Awesome, thanks! Is there a way to only have that default value set,
if the NewRecord button is pushed?
magmike - 30 Oct 2007 19:22 GMT
On Oct 30, 1:43 am, NevilleT <Nevil...@discussions.microsoft.com>
wrote:
> Is the letter form a different form to the client form, and is the client
> form still open when the letter form is open?  If so you can use the default
[quoted text clipped - 23 lines]
>
> - Show quoted text -

Or... is there a way to hide the form feilds if there are not any
current records (or letters) and only show a message saying there have
not been any letters sent, and a button that says, Send Letter Now,
that when pushed reveals the form, with default company id entered?

Thanks!
magmike - 30 Oct 2007 19:39 GMT
On Oct 30, 1:43 am, NevilleT <Nevil...@discussions.microsoft.com>
wrote:
> Is the letter form a different form to the client form, and is the client
> form still open when the letter form is open?  If so you can use the default
[quoted text clipped - 23 lines]
>
> - Show quoted text -

Awesome, thanks! And actually, since I am using a "new record" button,
I set the on click as such:

Private Sub AddNewCall_Click()
On Error GoTo Err_AddNewCall_Click

   DoCmd.GoToRecord , , acNewRec
   Forms!CallsForm!Combo26.Value = [Forms]![ProspectForm]![ID]

Exit_AddNewCall_Click:
   Exit Sub

Err_AddNewCall_Click:
   MsgBox Err.Description
   Resume Exit_AddNewCall_Click

End Sub

HOWEVER, would it be possible to have the form hide all fields if
there are not records matching criteria, or show a field that hides
all others and simply says: "There are no records" with a button to
add a new one?

Does that make sense?

magmike
NevilleT - 30 Oct 2007 23:18 GMT
Hi

A couple of things.  Firstly you can use a conditional statement and use the
visible property of the form.  Secondly for a message, you can either use a
label on the form that is hidden normally and you display it when
appropriate, or you can use a pop up message box.

There are a couple of ways to check if there are records.  One is to do a
record count and if it is zero, fire up the message and hide the fields.  
Once again I use a generic function to count records.  I just pass the SQL
statement and it returns the number of records.  You could use this for the
On Current event.

Dim strSQL as String

strSQL = "SELECT * from tblLetters where tblLetters.ClientNo = " &
Forms!frmClient!ClientNo

If funRecordCount (strSQL)>0 then  ' Records exist
   Me!txtClientName.Visible = True   ' Add any fields you want to make
visible
   Me!lblCustomWarning.Visible = False        ' Hide the warning message
 Else
   Me!txtClientName.Visible = False  ' Hide any fields
   Me!lblCustomWarning.Visible = True  ' Display the warning
End If

The function for funRecordCount can be stored in a module.

Public Function funRecordCount(strSQL As String) As Integer
   Dim dbs As Database
   Dim rst As Recordset
       
   On Error GoTo Error_funRecordCount

   Set dbs = CurrentDb
   Set rst = dbs.OpenRecordset(strSQL, dbOpenSnapshot, dbSeeChanges)
   
   ' Find the number of records.  First test records were found.
   If (rst.EOF = True) And (rst.BOF = True) Then
       funRecordCount = 0                                          ' No
records found
      Else
       rst.MoveLast                                                ' End of
the recordset
       funRecordCount = rst.RecordCount                            ' Number
of records
   End If
   
Exit_funRecordCount:
   On Error GoTo 0
   Set dbs = Nothing
   Set rst = Nothing
   Exit Function

Error_funRecordCount:
   MsgBox "An unexpected situation arose in your program." & funCrLf & _
          "Please write down the following details:" & funCrLf & funCrLf & _
          "Module Name: modGeneric" & funCrLf & _
          "Type: Module" & funCrLf & _
          "Calling Procedure: funRecordCount" & funCrLf & _
          "Error Number: " & Err.Number & funCrLf & _
          "Error Descritption: " & Err.Description
         
   Resume Exit_funRecordCount

End Function

> On Oct 30, 1:43 am, NevilleT <Nevil...@discussions.microsoft.com>
> wrote:
[quoted text clipped - 52 lines]
>
> magmike
magmike - 31 Oct 2007 00:08 GMT
On Oct 30, 5:18 pm, NevilleT <Nevil...@discussions.microsoft.com>
wrote:
> Hi
>
[quoted text clipped - 122 lines]
>
> - Show quoted text -

I am trying to implement this. However, now, when I open the letters
form I get the following error:

Compile Error:

User-defined type not defined.

While this message is displayed, the debugger comes up and is
highlighting "dbs as Database" in the code where Dim was in front of
it. Have I left something out?

thanks!
NevilleT - 31 Oct 2007 00:24 GMT
Sounds like references.  In the VBA screen go to Tools, References and make
sure the Microsoft DAO 3.6 Object Library is ticked and near the top (Usually
around row 3).  Depending on your version, you might have a different number
to 3.6.

Hope that helps

> On Oct 30, 5:18 pm, NevilleT <Nevil...@discussions.microsoft.com>
> wrote:
[quoted text clipped - 137 lines]
>
> thanks!
 
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.