Solved

opening form locks table in access

Posted on 2013-02-02
7
159 Views
Last Modified: 2013-02-02
on my open form event i am checking for the existence of columns in the underlying table:
the ideas was that if they all exist the form can get on and open. If a particular column didn't exist, i had hoped to close the form and create the fields which i tried with Each of the code segments work I am just not sure where to put them so that columns get created when necessary or if the columns exist the form opens.



Private Sub Form_Open(Cancel As Integer)
Dim a, b, c, d, e, f As Boolean
a = False
b = False
c = False
d = False
e = False
f = False

'   Me.Txt_Search_For.SetFocus
    'check fields in exportable and set boolean variables
    If CheckFieldExists("TblExportVinstems", "seq") = True Then a = True
 
    
    If CheckFieldExists("TblExportVinstems", "DoorsExtracted") = True Then b = True
    If CheckFieldExists("TblExportVinstems", "DVLACode") = True Then c = True
    If CheckFieldExists("TblExportVinstems", "CarwebCode") = True Then d = True
    If CheckFieldExists("TblExportVinstems", "VinConcat") = True Then e = True
    If CheckFieldExists("TblExportVinstems", "BodyDescription") = True Then f = True

Open in new window


'check that all tables existed
If a And b And c And d And e And f = True Then
'open form
else

DoCmd.Close

Dim x As Boolean
' FAILS HERE AS FORM IS STILL OPEN AND TBL LOCKED ******************
If a = False Then x = CreateField("TblExportVinstems", "Seq", dbLong)

If b = False Then x = CreateField("TblExportVinstems", "DoorsExtracted", dbLong)

If c = False Then x = CreateField("TblExportVinstems", "DVLACode", dbText)


If d = False Then x = CreateField("TblExportVinstems", "CarwebCode", dbText)


If e = False Then x = CreateField("TblExportVinstems", "VinConcat", dbText)


If f = False Then x = CreateField("TblExportVinstems", "BodyDescription", dbText)
end if

Open in new window

0
Comment
Question by:PeterBaileyUk
  • 4
  • 2
7 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 38846613
Try using an intermediate form whose purpose is to run this code, close itself and open the other form.

Or start with a blank recordsource and set the recordsource through vba after running that code.
0
 

Author Comment

by:PeterBaileyUk
ID: 38846620
i was just looking at autoexec but although i created the macro i am not sure how to edit the code
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38846626
I don't use macros much but I think there is a runcode command which lets you specify a function.   Your code would have to be placed in a separate function in module outside of your form.
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 38846629
Along the same lines as autoexec you can use open event code in a dedicated startup form if you have one. That is my preferred approach, all vba.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38846632
The startup form of course shouldn't be bound to the table you are changing.
0
 

Author Closing Comment

by:PeterBaileyUk
ID: 38846644
great thx
0
 
LVL 30

Expert Comment

by:hnasr
ID: 38846647
Current form (a) locks table for design.
Current form opens form (b), closes it self, frees table (a) for design.

Form (b) runs code in form_open event  to modify table (a), runs form (a), closes it self.

As a side note:
But why do you need that?
I prefer to separate table design issue from from form design issue. This gives better control over data types and avoid accidental creation of unwanted fields/field names. This complicates database maintenance.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question