Connection Problem 03-20-08


I'm new to access programming so I'm probably making some obvious mistake.

The following code comes from 'Beginning  Access 2003 VBA' by Denise

On page 130 of the book you can read:

1. Create a new database by selecting File ?New ?Blank Database and
specifying Ch5CodeExamples as the filename.

2. Create a new table in the database by selecting Tables from the Database
Window and clicking the Design button. Alternatively, you can select the New
button and then choose Design View

from the list. The table should be named tblContacts and should have the
fields illustrated in Figure 5.3. Note that the field sizes are listed as
part of the description for convenience

purposes only, so that, when creating the table, you can see what size to
set for each field.

3. Open the table from the Database Window and add at least one record to
the table.

4. Create a new form named frmContactsBound. Use the toolbox to drag and
drop 12 text box controls onto the form. Modify the Name property for each
text box to the following: txtLastName, txtFirstName, txtMiddleName,
txtTitle, txtAddress1, txtAddress2, txtCity, txtState, txtZip, txtWorkPhone,
txtHomePhone, and txtCellPhone, respectively. Also rename the Caption
property for the corresponding label of each text box, as shown in Figure

5. Add the following code to the Form_Load procedure of the frmContactsBound
form. You can do so by selecting the form in the Designer Window, viewing
the Properties dialog box for the form, selecting the Events tab, and then
selecting the Code Builder option from the On Load event.

Private Sub Form_Load()
    Dim cnCh5 As ADODB.Connection
    Dim rsContacts As ADODB.Recordset
    Dim strConnection As String
    'specify the connection string for connecting to the database

    strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & CurrentProject.Path & "\Ch5CodeExamples.mdb"
    'create a new connection instance and open it using the connection
    Set cnCh5 = New ADODB.Connection
    cnCh5.Open strConnection
    'create a new instance of a recordset
    Set rsContacts = New ADODB.Recordset
    'set various properties of the recordset
    With rsContacts
    'specify a cursortype and lock type that will allow updates
    .CursorType = adOpenKeyset
    .CursorLocation = adUseClient
    .LockType = adLockOptimistic
    'open the recordset based on tblContacts table using the existing
    .Open "tblContacts", cnCh5
    End With
    'if the recordset is empty
    If rsContacts.BOF And rsContacts.EOF Then
    MsgBox "There are no records in the database."
    Exit Sub
    'if the recordset is not empty, then bind the
    'recordset property of the form to the rsContacts recordset
    Set Me.Recordset = rsContacts
    End If
    'bind the controls of the form to the proper field in the recordset
(which has
    'the same field names as the tblContacts table from which it was
    Me.txtLastName.ControlSource = "txtLastName"
    Me.txtFirstName.ControlSource = "txtFirstName"
    Me.txtMiddleName.ControlSource = "txtMiddleName"
    Me.txtTitle.ControlSource = "txtTitle"
    Me.txtAddress1.ControlSource = "txtAddress1"
    Me.txtAddress2.ControlSource = "txtAddress2"
    Me.txtCity.ControlSource = "txtCity"
    Me.txtState.ControlSource = "txtState"
    Me.txtZip.ControlSource = "txtZip"
    Me.txtWorkPhone.ControlSource = "txtWorkPhone"
    Me.txtHomePhone.ControlSource = "txtHomePhone"
    Me.txtCellPhone.ControlSource = "txtCellPhone"

End Sub

6. Save the VBA code from the Visual Basic Editor by selecting the Save
button from the toolbar.

7. Save the form from the Form Designer by selecting the Save button from
the toolbar.

8. Open the form. You should see a screen similar to Figure 5.5.

9. Modify one of the existing records.

But when I open the form I get an error saying that the file is already in
use and cannot be used.

What can be wrong?

Thanks in advance

3/20/2008 9:04:06 AM
access.formscoding 7493 articles. 0 followers. Follow

0 Replies

Similar Articles

[PageSpeed] 0


Similar Artilces:

Public Folder Problem #12
I installed a second 2003 sp2 Exch server and have moved all of the existing mailboxes but can not view Public Folders under the admin group on the new server in esm. I get "token supplied to the function is invalid; ID # 80090308". Can anyone tell me what this is and how to correct it? Do you have require SSL set on the default virtual server? -- Best regards, Good Luck Oz Ozugurlu ____________________________ MCSE 2003 M+,S+, CCNA Http:// Http:// (Blog) "rw" wrote: > I installed a second 2003 sp2 Exch server and have mov...

OnPaint() Problem
Dear everyone: I am creating an IE browser using the microsoft web browser activeX control. After placing the microsoft web browser in a dialog box, i am trying to draw some ellipses on top of it. Those ellipses disappear if the dialog box in minimised/maximised or if another window is placed on top of the dialog. Can some one help me solving this problem? Thank you Here is some code: bool drawings = false; void CPaintNightMareDlg::OnPaint() { CPaintDC dc(this); // device context for painting if(drawings == TRUE){ drawShapes(dc); // this is a call to the drawShapes method } if...

Excel print out problem
I have export several files from Lotus Notes to MS XP Excel files. When the click print preview those files at Excel, the file is OK. However, if the file is more then 1 page, the 1 st row will be repeated on everypage after printing. If I delete the 1 st row, then the 2 nd row will become the 1 st row and the print out is OK. I try to clear all the format in the cell and then re-created the format at excel file but when the file print out, it will keep repeating the 1 st row again. Any help? ------------------------------------------------ ~~ Message posted from

Hi, Trying to make an inventory ledger that displays all products, with all their transaction no's and dates subcategorised under the products using excel pivot tables. The problem was that If i kept row fields as product, under that transaction date and under that transaction no then i could not get the running total to work properly. I made another cell in my source data called transaction date & transaction no, and put that under product and finally my running total started working properly. removed individual transaction date and transaction product row fields. I got another pr...

email domain problems
Setting up SBS2003 for a company "" The windows domain is abc.local. The pop3 connector goes out to get the email for who those use this server. The problem is sending to users at other locations that also use email addresses It seems that when sending email, Exchange first looks at local email addresses to decide where to route the email. For example, if has an account on the local server, then email for is put directly into his inbox. The problem arises in sending email to who does not have a local email ...

Problems installing to MS CRM 3
Installing MS CRM 3 (RTM code) with trial licence to SBS 2003 Server with SP1. Install reporting an error on SRS where the HTTP:\\SERVERNAME can't be reached. I note that the default web site doesn't have a host header - is this what is causing the problem ? Have already performed the recommended work around (deactivating loopback check) on SBS. Generally frustrated with this as we were all told that the installation was much simpler now !! ...

Multiple Outlook Problems
I am running Office XP. Recently I have been unable to open links in e-mail messages unless IE is already open. It tries to link, shows hourglass, but then goes back top teh email message. If IE is open, it works fine. Sometimes even have trouple opening Excel attachments unless Excel is already open. Tried fixing by using "detect and repair" in the Help menu. Now whenever I try to open Outlook I get four error messages in succession. Each referrs to an add-in that is missing or defective. The messaages are long but end as follows: ....\addins\msspc.ecf .....

problem printing booklet
I'm not very familiar with publisher, so please be patient. I have a friend who created a booklet in publisher in landscape format. She typed the text on both sides of the page and when she prints it the text changes to portrait format with a smaller font. Can anyone tell me what she should do? Please email me directly with 'Publisher' as the email header. Thank you. In page setup, be sure your friend is choosing booklet (In older versions it maybe called "special fold"). It will automatically set to landscape (in older versions you will have to tick the landscap...

Strange problem when saving excel 97 to Windows 2003 server
We just upgraded our File server from a NT 4.0 machine to a Windows 2003 Server machine (active directory + new hardware). We have several computers still running windows 98 and office 97. A couple of our windows 98+ Excel 97 users ran into a problem when saving simple (no macro) Excel documents on the server. Excel froze showing only a white screen. When checking the server folder in real time when this error occurred I saw that the document name that should have appeared in the drive was not there and instead a ever growing file named: "06D7A00" appeared. It kept growing (over 2 GB...

Windows 7 and Outlook 2007 problem
I updated to Windows 7, and reinstalled Office 2007. I cannot install Outlook, and when I go into Control Panel/Mail I get the message that the Exchange Server is not available. I cannot get past this. "doctoral student muma" <> wrote in message >I updated to Windows 7, and reinstalled Office 2007. I cannot install > Outlook, and when I go into Control Panel/Mail I get the message that the > Exchange Server is not available. I cannot get past this. Su...

Money 2004 Business and Invoice Designer Problem
When I click on Invoice Designer, Money displays an error message telling me that I have not accepted the End User License Agreement (EULA). I have reinstalled the product twice and accepted the agreement both times at installation. Has anyone encountered this and do they have a solution? ...

Installation Error 03-28-07
I'm installing CRM 3.0 onto SBS2003 R2 Premium with SQL2005 SP2 and I'm getting this error: The Reporting Services Report-Server http://servername/Reportserver cannot be validated. Error: The feature "Customizing Security Roles" is not supported in this edition of the Reporting Services. Is there any fix for this yet? this is a problem when sql2005 sp2 is installed. you need to uninstall sql server, reinstall (without applying sp2), then install crm 3. I believe there is a sp2a availiable that is better for crm though I haven't tried it. I also have not tried i...

sorting problem #2
Hi! I have problems generating a rutine that will automatically sort my sheet. The sheet is in this format (always 2 columns only the rows may vary) a 1 a 2 a 3 b 2 b 1 c 7 d 1 d 3 d 4 d 6 d 7 e 7 I want it to look like this: a b c d e 1 2 7 1 7 2 1 3 3 4 6 7 Anyone know what vba code to use to get this done? /Colargol hi this is not a sorting problem. it's a transposing problem. I pasted your two columns in a blank workbook and wrote this macro. the result was what you want it to look like. in my set up, the two columns of data were in columns a and b starting at a1 wi...

Problems with Vanguard Fund Data
I believe I have set up my accounts correctly and download active money statements from Vanguard, but although I have a total of about 6 different funds, the transactions all get lumped into 2 or 3 of them. I have to manually move them to correct funds. Does anyone else have this problem with Vanguard funds, or a solution? I have the same problem...even when I have shown one of the accounts as closed.Also, the transactions don't add up to the account balance...really weird. Whats the point of having online updates that don't work. any suggestions?? "Jim" wrote: > ...

problem opening 2003 pub file
I have tried to email a Publisher document to another computer, both of which have Pub 2003 installed. I have been successful with other documents, but this one gives the recipient a message that "Publisher cannot open this version”.. The document in question was indeed originally written using Publisher 2000, but has been modified and saved many times over the years in P-2003, and I have no problem opening it at home. Is there a way that I can save it in such a way that it will be acceptable at the recipient’s end? Does that recipient use Norton AV? -- JoAnn Paules MVP Micro...

Cells Right Click Menu Problem
I have added the following code to my Personal.XLS. Sub Create_Unlock_Cells_Right_Click() 'Set up Unlock Cells on Right Click Menu With Application.CommandBars("Cell").Controls.Add(, , , 6, (temporary)) .BeginGroup = True .Caption = "Unlock Cells" .OnAction = "Unlock_Cells" End With End Sub Its purpose is to add a 'Unlock Cells' item to the right click menu for cells. The subroutine "Unlock_Cells" simply unlocks the cell or range of cells selected and works just like I want it to work. The 'Unlock C...

Payables batch entry problem
Hi everyone, Our payables dept has a problem with Payables Batch Entry where when they edit an existing or enter a new batch and then select computer check as the origin the post option gets grayed out. They're claiming it never was like that and that happened just recently. What could be the cause of it? I've checked the posting options under setup and nothing sticks out at me. I've also checked for stuck batches or anything that might be suspect. Thanks, -- Jim Bourque Jim, Cheque Batches do not get Posted from the Batch Entry Window, they need ...

Problem with language and dates in Excel on a Mac
Hi, I've got a problem with excel for Mac - I've tried absolutely everything I can think of and can't seem to fix it... The basic problem is that dates appear in french (specifically, the month name). This is despite the fact that I've set every preference I can find to "English". So 10/07/2006 turns into 10-juil-2006 instead of 10-july-2006. If I look in the language preferences in excel, it's set to English. The language preferences in MaxOSX are also set to English. When I look at the cell format box, it's selected "Date" and the sample form...

IE8 losing connection
Love the browser except almost each time I use it, it ends up losing the connection and giving me the choice of closing program or looking for a solution and closing the program. Never had this problem before. I have ended up going back to firefox because of the nuisance value. Am I doing anything to cause this and is it a common occurrence? Is there going to be a fix issued soon? I'm sure that I can't be the only one having this problem. Always state your full Windows version (e.g., WinXP SP3; WinXP 64-bit SP2; Vista SP1; Vista 64-bit SP2; Win7; Win7 64-bit) as wel...

Simple Problem Using Outlook for newsgroups
Greetings and thanks for reading! I am relatively new to using Outlook, but have started using it as a newsgroup viewer. The only newsgroup I have been using is for help with XP (microsoft.public.windowsxp.general). Yesterday, I tried to view another newsgroup for palm pilots, whose link i found at 01-Palm-Newsgroups-.html However, when I click on the link, Outlook opens with an error pop-up which reads: "The newsgroup 'comp.sys.handhelds' was not available on the news server ''" Under &...

Colour Palette Problem
When I click on the colour palette, the red option has be replaced with grey. When I hover over the new grey it does say that it should be red. This problem occurs randomly, but the wrong colour once there will stay untill I reboot. I use a lot of spreadsheet during the day, some of these have been created by other people. My assumption is that within one of the spreadsheets, there is some VBA code that changes the colour pallete. Does anyone else suffer the same problem? Is my assumption valid? Can anyone advise me on this problem? Many Thanks, Simon ...

RFX_Date & CTime and RFX_OleDateTime & COleDateTime problems
This one's a real hair puller. Please help me out. I've got a database Query class derived from CRecordset. The Query (stored procedure) is called correctly by my app using the Requery() method and extracts the correct records from my Access 2002 database. Most of my class's field variables are updated perfectly -- with the exception of those of type CTime exchanged with RFX_Date. All the returned values come back equal to zero. Research of this newsgroup showed that CTime field variables need to be initialized in the constructor, but that didn't help any. There was also a ...

Office 2007 Multi Language install problem 12-15-09
Hi, I want to apply an Office 2007 language pack to an existing Office 2007 (English) installation. I've followed all steps as described here: * I've copied all the Dutch folders (,, ...*.nl-nl) to a seperate folder * edited the\config.xml file as described (see attachment) * start the setup from the office 2007 setup-folder (setup.exe /config c:\mui\nl\\config.xml) the setup runs successfully. When I want to select Dutch as the interface language via St...

I'm having some problems with the MoneyCentral Portfolio...
I used to use the MoneyCentral Portfolio a lot, but I haven't gone there in many months. When I accessed it yesterday, it started creating files on my hard drive... By the time I stopped it, it had created 1519 files, all same size (3732 KB), for a total of 5.4 GB. All files are named "my portfolioXXXX.mny". My hard drive is getting full, so I didn't want to let it run forever. Does anyone know what these files are? and why they got created? I remember there is a support option once you get in the portfolio application, but since I can't get in... Please hel...

money 2004 -> money 2006 toolbar problem
Just upgraded from 2004 to 2006 via purchased box. the toolbar that has "home banking bills reports budget investing planning taxes" only partially works clicking on investing planning or taxes does nothing. No errors but no action either. When at the home page in the left column clicking on Investing Home, Planning Home, and Taxes Home also does nothing. Any ideas what I set up wrong. (I just let it automatically update the old money file). Thanks, Michael ...