473,566 Members | 2,785 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Create New Blank Record In a Form

10 New Member
Hi

Using Access 2007, I have a form created that uses a combo box to select records from an underlying table. I want the user to be able to create a new record with absolutely no pre-set data in it to allow them to key in the new data themselves. I am really stuck as to how to do this.

I have added a cmd button to the form and have tried using the following code that I picked up from here:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdNew_Click()
  2.  
  3.         Dim dbsVehicle_Sales As DAO.Database
  4.         Dim rsttblAECarAuctionDisposals As DAO.Recordset
  5.  
  6.         Set dbsVehicle_Sales = CurrentDb
  7.         Set rsttblAECarAuctionDisposals = dbsVehicle_Sales.OpenRecordset("tblAECarAuctionDisposals", dbOpenDynaset)
  8.  
  9.         With rsttblAECarAuctionDisposals
  10.             .AddNew
  11.                 ![Registration] = strStringVariable
  12.                 ![Tag] = strStringVariable
  13.                 ![VAT Status] = strStringVariable
  14.                 ![Vehicle Description] = strStringVariable
  15.                 ![Buyer] = strStringVariable
  16.                 ![Date Sold] = dteDateVariable
  17.                 ![Sale Price (Gross)] = curCurrencyVariable
  18.                 ![VAT] = curCurrencyVariable
  19.                 ![Net Proceeds] = curCurrencyVariable
  20.                 ![Mileage] = lngLongVariable
  21.                 ![Year/Letter] = strStringVariable
  22.             .Update
  23.         End With
  24.  
  25.  
  26. End Sub 


When I execute, it tells me run-time error 3058; Index or primary key cannot contain a Null value.

Registration is my primary key.

Can anyone help please?
Feb 14 '08 #1
8 9902
Khriskin
20 New Member
I'm a little confused as to what you are trying to accomplish. As a disclaimer, I work in Access 2000 and 2003, so 2007 may have features I don't know about. However, the code you included in the post doesn't seem to do what you are looking for.

The code is setup to create a new record within the table, but it does so using variables that are not defined (strStringVaria ble, dteDateVariable , etc). Thus all of the variables default to NULL, which spawns the 3058 error you are getting. Also, you set dbsVehicle to be a copy of your current database, but then never use it in the code.

If you are just trying to let the user enter a new record, it might be easier to have the button open a pop-up form that is set to Data Entry. This would give the user a blank record to fill in, as well as allow you some control over the input validation.

Hope that helps! ^_^
Feb 14 '08 #2
jimrand
10 New Member
Ok, thanks. How do I get the button to open a pop up form for them to enter a new record?
Feb 14 '08 #3
Khriskin
20 New Member
You'd need to create the form first, then you can use the DoCmd.OpenForm to open it, just like an ordinary form. Make sure you set the pop-up form to Pop Up (opens in front of other windows), Modal (keeps focus until closed), and Data Entry (new record entry only).

Also, you'll need to do some basic error trapping on the pop-up form to make sure the users don't close it before all the information is gathered (as well as put in valid information).

How familiar are you with creating forms? How access-savvy are your target users? This may be something you can create with the built-in Form Wizards, but it may also require some coding.

Hope that helps! ^_^
Feb 14 '08 #4
jimrand
10 New Member
You'd need to create the form first, then you can use the DoCmd.OpenForm to open it, just like an ordinary form. Make sure you set the pop-up form to Pop Up (opens in front of other windows), Modal (keeps focus until closed), and Data Entry (new record entry only).

Also, you'll need to do some basic error trapping on the pop-up form to make sure the users don't close it before all the information is gathered (as well as put in valid information).

How familiar are you with creating forms? How access-savvy are your target users? This may be something you can create with the built-in Form Wizards, but it may also require some coding.

Hope that helps! ^_^
Right, I already have my form created and I am attempting to use it as both a form to display data, but also to allow input. Would I be better to use one form to display the data that is locked and have a second form for input that is only displayed when the users select the "New Record" button?

I have only been doing this for a short space of time and as you can probably guess I am having to learn as I go along!!

As far as error trapping goes, that's going to be something new for me as well, but I suppose the sort of thing you refer to is to ensure that all relevant fields are completed before the form allows them to exit? I'll give it a go and if/when I get stuck, there'll be a new post!

Thanks for your help....
Feb 15 '08 #5
blad3runn69
59 New Member
DoCmd.GoToRecor d , , acNewRec
Feb 15 '08 #6
jimrand
10 New Member
DoCmd.GoToRecor d , , acNewRec
That's what I wanted - thanks!! Realise it's crude, but it does what I need.
Feb 15 '08 #7
Khriskin
20 New Member
Right, I already have my form created and I am attempting to use it as both a form to display data, but also to allow input. Would I be better to use one form to display the data that is locked and have a second form for input that is only displayed when the users select the "New Record" button?
Sorry about that! I misunderstood what you were trying to do, I thought the main form you were talking about was for displaying data only, not that you also wanted to use it for data entry. (Doh!)

Glad you found something that works! ^_^
Feb 15 '08 #8
jimrand
10 New Member
Sorry about that! I misunderstood what you were trying to do, I thought the main form you were talking about was for displaying data only, not that you also wanted to use it for data entry. (Doh!)

Glad you found something that works! ^_^
No worries, I think it was much more me misleading you by trying to use code (in the first post) that was clearly not understood by me!!!

Anyway, thanks for trying to help despite me confusing the heck out of it!!
Feb 15 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

19
6965
by: Joe Scully | last post by:
Hi all, I am having trouble with access adding a blank record to a subform everytime I finish entering data and closing the form. (The form and subform are based on the one table) When entering data into the subform I get the pencil icon to show data addition, but underneath the record I am inputting data the record is blank with a...
2
6673
by: Johm | last post by:
How can i go to the next blank record in the table , such a blank record exists ? In my form Customers, i have a command button with the following command : DoCmd.GoToRecord , "", acNewRec DoCmd.GoToControl "CompanyName" The above command is OK, but i want to amend it somehow . Do to some
2
1471
by: Cassandra | last post by:
My data entry form has thirty one fields. After I go to a new record and enter all the fields, how can I create another new record out of the same data? Sometimes when I am entering new records, only two or three fields change from one new record to another. If I could create a new record out of the same data and then edit the two or three...
6
1527
by: Robert | last post by:
Hello, Accessors What I would like to do is create a multi-record table update. I have a table and a form for it. I want to modify it so that there is a new field (textbox) (not bound to a table field) on the form wherein the user enters a number to specify how many new records to add to the table as opposed to the 1 record which is...
1
6525
by: Tim Graichen | last post by:
Hello, I have a main form with one subform. The main form displays a record from TableOne (PCID) This is a corporate software tracking utility that works like this: Main form...Choose PCID (from TableOne) Subform..Display / Add software (from TableTwo) (linked via PCID)
5
2439
by: ChadDiesel | last post by:
My basic question is why does my print report button on my subform print a blank report when my cursor is on a blank entry line? Here is a more detailed explanation of my problem. I have a form that contains shipment destination information and a subform that contains boxes for that shipment. The main form is a table called Ship_Info,...
4
12420
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is this: can Access create the document and place it as an OLE object to the relevant table? Any help is greatly appreciated. Ricky
7
3404
by: FNA access | last post by:
I have a mainform that has a subform in the detail section and a subform in the footer section.(Both subforms are in datasheet view) When I click the navigation button to create a new record on the mainform. My subform in the detail section goes blank (this is what I want) but my subform in the footer section appears to have the data from the...
12
3260
by: tekctrl | last post by:
Environment; Win2K PC with 1Gb of RAM and plenty of HD space running Access 2002 Issue; Access presents a blank data entry form in the Forms view when the New Record icon is used. However, it won't allow any fields to have data entered into them. I can edit & save existing records without problem. When I go into the Tables view, I can add...
1
6551
by: cvillav | last post by:
Hello, I am new to Access and this forums, I have two tables and two forms to display the data. Tables Tbuilding Tcriteria Forms fmbuilding
0
7666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8108
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7644
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7951
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1201
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
925
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.