Datasheet Form for Viewing Only...?

P

Pamela

I am trying to duplicate a program that has Access as it's underlying db
which has a datasheet view of all records. The record data cannot be changed
in this form but can be selected and then edited using a command button that
unlocks the fields in a subform below. The subform does not update the
Datasheet form until a Save command button is used. The records in the
Datasheet form need to be able to be sorted by each field. One other note to
keep in mind is that ultimately I'll need to be able to attach multiple
images to each record...

Any thoughts on how to achieve this would be greatly appreciated for this
newbie!
 
S

strive4peace

Sort123
~~~

Hi Pamela,

It is not a good idea to have two forms open that use the same table in
their RecordSource.

Never-the-less, for the form where you do not want to allow changes,
make the form RecordsetType --> Snapshot

"The subform does not update the Datasheet form until a Save command
button is used."

If you move off a record, the data will automatically get saved; that is
the way that Access works. If you do NOT want it to be saved unless you
explicitely click a Save button, you will need to write code to stop it

"The records in the Datasheet form need to be able to be sorted by each
field."

then, instead of a Datasheet view, use a Continuous view -- that way,
you can put code on the click event of each column header to sort by
that column -- and here is a function you can use to do that:

'~~~~~~~~~~~~~~~~~~~~~~~~~~ Sort123
Function Sort123( _
pF As Form _
, pField1 As String _
, Optional pField2 = "" _
, Optional pField3 = "" _
) As Byte

'sort form by specified control(s)

'written by Crystal
'strive4peace2008 at yahoo dot com

'PARAMETERS
'pf -- form reference (in code behind form --> Me)
'pField1 -- name of control for first sort
'pField2 -- optional, name of control for second sort
'pField3 -- optional, name of control for third sort

'sending the same sort fields
'toggles Ascending and Descending order

'EXAMPLE
'in code behind form:
' --> Sort123 Me, "Controlname1", "Controlname2"
'property assignment -- ie: click event of column header:
' --> =Sort123([form], "Controlname")
' --> =Sort123([form], "Controlname1", "Controlname2", "Controlname3")

'set up Error Handler
On Error GoTo Proc_Err

Dim mOrder As String _
, mOrderZA As String

If Len(Trim(pField1)) > 0 Then
mOrder = pField1
mOrderZA = pField1 & " desc"
End If
If Len(Trim(pField2)) > 0 Then
mOrder = (mOrder + ", ") & pField2
mOrderZA = (mOrderZA + ", ") & pField2
End If
If Len(Trim(pField3)) > 0 Then
mOrder = (mOrder + ", ") & pField3
mOrderZA = (mOrderZA + ", ") & pField3
End If


If pF.OrderBy = mOrder Then
pF.OrderBy = mOrderZA
Else
pF.OrderBy = mOrder
End If
pF.OrderByOn = True

Proc_Exit:
Exit Function

Proc_Err:
MsgBox Err.Description, , _
"ERROR " & Err.Number _
& " Sort123"

Resume Proc_Exit

'if you want to single-step code to find error, CTRL-Break at MsgBox
'then set this to be the next statement
Resume

End Function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Warm Regards,
Crystal

remote programming and training

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
:) have an awesome day :)
*
 
S

strive4peace

correction:

control should be --> field
in the remarks for Sort123


Warm Regards,
Crystal

remote programming and training

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
:) have an awesome day :)
*



Sort123
~~~

Hi Pamela,

It is not a good idea to have two forms open that use the same table in
their RecordSource.

Never-the-less, for the form where you do not want to allow changes,
make the form RecordsetType --> Snapshot

"The subform does not update the Datasheet form until a Save command
button is used."

If you move off a record, the data will automatically get saved; that is
the way that Access works. If you do NOT want it to be saved unless you
explicitely click a Save button, you will need to write code to stop it

"The records in the Datasheet form need to be able to be sorted by each
field."

then, instead of a Datasheet view, use a Continuous view -- that way,
you can put code on the click event of each column header to sort by
that column -- and here is a function you can use to do that:

'~~~~~~~~~~~~~~~~~~~~~~~~~~ Sort123
Function Sort123( _
pF As Form _
, pField1 As String _
, Optional pField2 = "" _
, Optional pField3 = "" _
) As Byte

'sort form by specified control(s)

'written by Crystal
'strive4peace2008 at yahoo dot com

'PARAMETERS
'pf -- form reference (in code behind form --> Me)
'pField1 -- name of control for first sort
'pField2 -- optional, name of control for second sort
'pField3 -- optional, name of control for third sort

'sending the same sort fields
'toggles Ascending and Descending order

'EXAMPLE
'in code behind form:
' --> Sort123 Me, "Controlname1", "Controlname2"
'property assignment -- ie: click event of column header:
' --> =Sort123([form], "Controlname")
' --> =Sort123([form], "Controlname1", "Controlname2", "Controlname3")

'set up Error Handler
On Error GoTo Proc_Err

Dim mOrder As String _
, mOrderZA As String

If Len(Trim(pField1)) > 0 Then
mOrder = pField1
mOrderZA = pField1 & " desc"
End If
If Len(Trim(pField2)) > 0 Then
mOrder = (mOrder + ", ") & pField2
mOrderZA = (mOrderZA + ", ") & pField2
End If
If Len(Trim(pField3)) > 0 Then
mOrder = (mOrder + ", ") & pField3
mOrderZA = (mOrderZA + ", ") & pField3
End If


If pF.OrderBy = mOrder Then
pF.OrderBy = mOrderZA
Else
pF.OrderBy = mOrder
End If
pF.OrderByOn = True

Proc_Exit:
Exit Function

Proc_Err:
MsgBox Err.Description, , _
"ERROR " & Err.Number _
& " Sort123"

Resume Proc_Exit

'if you want to single-step code to find error, CTRL-Break at MsgBox
'then set this to be the next statement
Resume

End Function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Warm Regards,
Crystal

remote programming and training

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
:) have an awesome day :)
*



I am trying to duplicate a program that has Access as it's underlying
db which has a datasheet view of all records. The record data cannot
be changed in this form but can be selected and then edited using a
command button that unlocks the fields in a subform below. The
subform does not update the Datasheet form until a Save command button
is used. The records in the Datasheet form need to be able to be
sorted by each field. One other note to keep in mind is that
ultimately I'll need to be able to attach multiple images to each
record...

Any thoughts on how to achieve this would be greatly appreciated for
this newbie!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top