Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic form creating form2 by default, how to reset or capture 2

Status
Not open for further replies.

EmployedAgain

Programmer
Jun 8, 2004
11
0
0
US
I have a dynamic form that was working very well until it crashed yesterday when I was changing the code and now instead of the default of form1 being created it comes up with form2 and of course the code breaks.

I've looked everywhere for answers but havent had any luck. My 2 questions are:

1. How do I reset that system default back to form1 for a newly created form (I compacted already, I thought it was maybe in the hidden sys files but I'm not seeing it)

and more importantly

2. How do I code to find out what form was just created through the createform method instead of assuming it will always be form1, in case this ever happens to the end user.

TIA, btw I'm using access 2003. If only createform would let you specify the form name!

TIA
B
 
You must have a Form1 somewhere, I think. The default form is always Form + Next Number, so:

Code:
Sub NewForm()
    Dim frm As Form
    
    ' Create form based on Customers form.
    Set frm = CreateForm
    DoCmd.Restore
    ' Set RecordSource property to Customers table.
    frm.RecordSource = "Customers"
    frmName=frm.Name
End Sub

Have a look in the Access FAQs and fora for Decompile, it is very useful.
 
to get the name

Dim frm as form
set frm = createform
msgbox frm.name

to clear delete form1 from your querydefs collection
 
I was able to rename a form to form1 and proceeded to delete it and that didnt reset the autonumbering of the forms, just proved to me there wasnt a hidden form somewhere. I gave up and dumped all the objects and code into a new empty DB and that solved that issue. I swore there was a way to do it through the system tables but regardless #1 is solved.

#2 is getting close (thanks gol4) I never think of easy ways to do things! So I now I want to have a string variable called DynFrm that stores the frm.name value. I'm sure I should know this but whats the syntax to refer to that variable instead of form1 in a statement such as:

Set ButtonMdl = Forms![form1].Module ' refer to the module


This looks like the only place I dont use frm.name already.

Thanks ALL!!!!


TIA
B
 
Replace Forms![form1] with Forms(frm.Name)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thats it! I have removed all references to form1 and its working great, thanks much!!!!

TIA
B
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top