Solved

opening form locks table in access

Posted on 2013-02-02
7
162 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

688 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