Programmatically update forms in design view

B

Biz Enhancer

Hi,
I have a problem with updating a label on multiple forms.

The scenario is that on each form I have a non-visible label that has a
number for its caption value.
Each form has a different number. This label named "fmno" supplies error
logging as well as a user rights functions.
The problem is that when I import forms into a new application I wish to
update the fmno.caption value programmatically by creating a recordset and
opening, updating, and closing each form in the recordset. I can't open the
forms in a Normal view as the fmno.caption value is incorrect and prevents
the form from opening (security routine on Form.Open). I can't pull the value
through on form.open as this would substantially weaken the security aspect.
Therefore I am trying to do this via the Design view. Code as follows:
********Code Start************
Private Sub Command15_Click()
On Error GoTo Errtrp
Dim Erm As String, fm As String, MyDB As Database, rs As Recordset, e As
String, k As String, t As String
fm = Me.fmno.Caption
Erm = "F" & fm & "/C15cl"
Set MyDB = CurrentDb()
Set rs = MyDB.OpenRecordset("SELECT frmtbl.jid, frmtbl.title FROM frmtbl;")

While Not rs.EOF
e = rs.Fields(1)
k = "" & rs.Fields(0) & ""
t = "" & e & ""
DoCmd.OpenForm e, acDesign, , , acFormEdit, acWindowNormal
Forms(t)(fmno).Caption = k
DoCmd.Close acForm, e, acSaveYes
rs.MoveNext
Wend
Exittrp:
Exit Sub

Errtrp:
Call faulttrp(Erm, Err.Number, Err.Description)
Resume Exittrp

End Sub
****Code End**********
Running this I get an error 438 "Object doesn't support this property or
method"
Any ideas on how to get around the problem?

Appreciate any help.
Thanks,
Nick.
 
A

Allen Browne

Opening forms in design view is not a good solution. It will prevent you
creating an MDE, so at some point in the future, will stymie you.

If you want to do it anyway, make sure the form is not already open before
you open it in design view.

Particularly if you already have the information you need in a table, this
seems like an unnecessary approach. You might investigate whether the ID of
the MSysObjects table could already give you a unique identifier for each
form.
 
B

Biz Enhancer

Hi Allen,
Thanks for the reply.
The routine that I am running is done before the creation of an MDE.
Essentially it is one of the last steps I'll take before compiling to MDE to
ensure that all the fault tracing is going to report accurately and that
there is no confusion between rights assignment on forms. After that it won't
be used in the production version.
The table which this routine draws from holds more data than just the
formname and id. It also holds aliases and descriptions for the user rights
assignment and another "checking" value that the form looks up on open and
compares with the users assigned rights.

Because the value is held in various tables such as changeslog, faultlog,
userrights I was wanting to keep the value down to 3 digits or less to
minimise the tables/database size and to keep the data speed up over VPN. (
The backend is MySQL)

As far as you are aware, is it possible to update label captions
programmatically in design view?
Regards,
Nick.
 
A

Allen Browne

Yes: you certainly can assign a different value to the Caption property of a
Label control with the form is open in design view.
 
G

George Nicholson

Forms(t)(fmno).Caption = k

wouldn't that be

Forms(e).fmno.Caption = k
or
Forms(e).Controls(fmno).Caption = k
?
 
B

Biz Enhancer

Thanks George!

I knew there had to be something I was missing. Not the first time you have
assisted me either. I have appreciated yours and others wisdom in these
forums as it has assisted my learning greatly. Thank you for taking the time
to impart your knowledge.

Regards,

Nick.
 

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