Creating a form programmatically

F

fulltime

Hi all,

I am using the codes beneath to create a form programmatically, the
form tat it shld base itself on is a current form tat exists in the
database, "Danish"

Private Sub NewForm_Click()

Dim frm As Form

'Create a new form based on the XXXXX form
Set frm = CreateForm(, "Danish")
DoCmd.Restore

frm.RecordSource = "Danish Q"

End Sub

When the form is created, it does set its record source to Danish Q BUT
the form is blank. I thought by specifying the template, i.e Danish, it
shld also copy the textboxes and buttons on the Danish form as well??

My main objective is to make a copy of the form, titled Danish, then
change the record source to Chinese Q, how can i achieve it
programmatically?

Thanks.
FT
 
A

Albert D.Kallal

Are you just trying to change the record source of the form...or do you
actually need another copy of the form?

To change the record source of the form, simply go

docmd.OpenForm "Danish"
forms!Danish.ReocrdSource = "Danish Q"

So, there is no need to create a new form..but why not just modify the
existing forms record source as above?
 
T

tina

....and if that single form can be bound to different tables, without
changing the ControlSource properties, then the fields in those tables must
at least have identical names - and presumably *are* identical fields, as
regards data type and the data they store. so the next question is: why are
you storing this data in separate tables? sounds like you need to read up on
normalization principles, and review your tables/relationships design. see
http://home.att.net/~california.db/tips.html#aTip1 for more information on
normalization.

hth
 
F

fulltime

after reading the above posts, it has set me thinking.. Below are the
requirements of my language database

Bascially, i have abt 10 languages, eg, danish, dutch, english,
chinese, etc.
So my form is used to display the predefined strings tat are stored in
the table..

Based on wat i read, do your mean tat i can define a COMMON form, eg,
"MAIN", then everytime, it opens, i just change the record source to
the corresponding query/language tat i desire?

docmd.OpenForm "Main"
forms!Danish.ReocrdSource = "Danish Q"

Is the above workable?
 
F

fulltime

thks to tina and Albert D.Kallal , your managed to point out my error
in my design... however, it brings me to my next question..

In the language database that i am creating, I will allow the user to
import an EXCEL file tat stores some strings in that language. So
depending on the length of the string, i need to write a query. This
query is FIXED, onli that if the length of the string is longer, i will
need to extract more variables. I managed to use VBA to code this
query, but my question is how can i store this query in the DataBase?

Thks..
 
T

tina

well, you're welcome for the help - and i hope that means that you are now
using ONE table for *all* of the language records, instead of storing each
language in a different table; and simply including an additional field in
that one table, to designate the language for each record.

as for your second question, i don't think i'm following you. if you built
the query in VBA, as a SQL string, you can simply run it in VBA whenever you
need it. or, if you want to save the SQL as a query object in the database,
then paste it into the SQL View pane of a new query. note that if you're
using any variables in the SQL string, you'll have to replace them with
parameters, form references, functions, or whatever is necessary to return
the values you need to the query (because query objects cannot use VBA
variables).

hth
 

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