Retrieving data from a table

B

Becky

hello to all

I have an application with about 40 forms and I want to control the size and
position of each of these forms when it opens. I currently do this with code
in each form's Open event like...
DoCmd.MoveSize 150, 250, 1100, 1850

But, I've noticed that there are only 5 different MoveSize settings spread
among all 40 forms. I'd like a way to put these moveSize values in a table,
then have each form look up its values when its Open event is executed. As a
very rusty coder, could some kind soul help me with this?

Much thanks
Becky
 
T

Tom van Stiphout

On Sat, 27 Dec 2008 14:15:00 -0800, Becky

In each Form_Open event write:
PositionMe Me

In a standard module write:
Public Sub PositionMe(frm As Form)
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("tblScreenPositions",
dbOpenSnapshot)
rs.FindFirst "FormName='" & frm.Name & "'"
If rs.NoMatch Then
MsgBox "Aarrcchhh, you did not enter coordinates for form " &
frm.Name
Else
DoCmd.MoveSize rs!Right, rs!Down, rs!Width, rs!Height
End If
rs.Close
Set rs = Nothing
End Sub

Create a new table named tblScreenPositions, with fields
FormName, text255, required, PK
Right, number, long integer, required
Down, number, long integer, required
Width, number, long integer, required
Height, number, long integer, required

-Tom.
Microsoft Access MVP
 
B

Becky

Perfect! Exactly what was needed. Thanks, Tom.

Tom van Stiphout said:
On Sat, 27 Dec 2008 14:15:00 -0800, Becky

In each Form_Open event write:
PositionMe Me

In a standard module write:
Public Sub PositionMe(frm As Form)
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("tblScreenPositions",
dbOpenSnapshot)
rs.FindFirst "FormName='" & frm.Name & "'"
If rs.NoMatch Then
MsgBox "Aarrcchhh, you did not enter coordinates for form " &
frm.Name
Else
DoCmd.MoveSize rs!Right, rs!Down, rs!Width, rs!Height
End If
rs.Close
Set rs = Nothing
End Sub

Create a new table named tblScreenPositions, with fields
FormName, text255, required, PK
Right, number, long integer, required
Down, number, long integer, required
Width, number, long integer, required
Height, number, long integer, required

-Tom.
Microsoft Access MVP
 

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