473,325 Members | 2,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Create New Blank Record In a Form

10
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 9879
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 (strStringVariable, 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
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
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
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
DoCmd.GoToRecord , , acNewRec
Feb 15 '08 #6
jimrand
10
DoCmd.GoToRecord , , acNewRec
That's what I wanted - thanks!! Realise it's crude, but it does what I need.
Feb 15 '08 #7
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
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
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...
2
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...
2
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,...
6
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...
1
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...
5
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...
4
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...
7
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...
12
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...
1
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.