Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 17th, 2007, 11:29 AM
Authorized User
 
Join Date: Jan 2006
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default Open a form to enter a new record

i'm trying to create an order form that if the customer is not in the database you can click on a cmd button to open the customer form to enter in the new customer. I would like it to open right up with out being able to select through the existing customers but to open up to a blank form that will record the info right into the customer table. this is what i have so far:

Private Sub CmdNewCustomer_Click()
' This code created in part by Command Button Wizard.
On Error GoTo Err_CmdNewCustomer_Click

    Dim strDocName As String
    Dim stLinkCriteria As String

    strDocName = "F_Client"
    DoCmd.OpenForm strDocName, , , stLinkCriteria

    ' Close WorkOrder form.
    DoCmd.Close acForm, "T_WorkOrder"

    ' Give ClientName control focus.
    Forms![F_Client]!Client.SetFocus

Exit_CmdNewCustomer_Click:
    Exit Sub

Err_CmdNewCustomer_Click:
    MsgBox Err.Description
    Resume Exit_CmdNewCustomer_Click

End Sub


THIS IS WHAT IS THROWING ME!!! IS THIS WHAT I NEED TO FIX? AND HOW DO I FIX IT?
    DoCmd.OpenForm strDocName, , , stLinkCriteria

Now this was the best solution i had but am open to better suggestions if this is not the best way to approach this. my goal is to eliminate duplicate customer records. maybe i need a different appraoch i'm not sure

 
Old August 17th, 2007, 12:36 PM
Authorized User
 
Join Date: Jun 2003
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default


I may be misunderstanding the problem there are probably two ways to do this

I am assuming you already have code to establish the presence or lack of a customer in the dbase


Place a button on the object currently being viewed (presumably an open form in Edit Mode (all customers available)

place the following code in the click event of the said button

Private Sub CmdAddCust_Click()
On Error GoTo Err_CmdAddCust_Click

'Goes directly to a new record to add customer to the table
    DoCmd.GoToRecord , , acNewRec

Exit_CmdAddCust_Click:
    Exit Sub

Err_CmdAddCust_Click:
    MsgBox Err.Description
    Resume Exit_CmdAddCust_Click

End Sub

If you wish to use an entirely different form then just add code to the button similar to the following

Private Sub CmdMMfromCust_Click()
On Error GoTo Err_CmdMMfromCust_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmAddCustomer"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    DoCmd.GoToRecord , , acNewRec
    DoCmd.Close acForm, "frmEditCustomers"

Exit_CmdMMfromCust_Click:
    Exit Sub

Err_CmdMMfromCust_Click:
    MsgBox Err.Description
    Resume Exit_CmdMMfromCust_Click

End Sub

I hope I have understand the problem if not I am sure someone else on the forum will be able to assist

MF







Similar Threads
Thread Thread Starter Forum Replies Last Post
Open Form to Add New Record is Blank echovue Access 9 July 10th, 2013 03:38 PM
Open Form, run query, open form Grafixx01 Access 7 April 26th, 2007 11:32 AM
Open CMD, NSLookup, enter name, return IP mmcdonal VBScript 3 December 19th, 2006 08:40 AM
Record.Open doesn't work CarlHu BOOK: Beginning ASP 3.0 4 October 19th, 2005 09:37 PM
submit the form by hitting the enter key rajiv_software Classic ASP Basics 1 April 26th, 2005 07:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.