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: - Private Sub cmdNew_Click()
-
-
Dim dbsVehicle_Sales As DAO.Database
-
Dim rsttblAECarAuctionDisposals As DAO.Recordset
-
-
Set dbsVehicle_Sales = CurrentDb
-
Set rsttblAECarAuctionDisposals = dbsVehicle_Sales.OpenRecordset("tblAECarAuctionDisposals", dbOpenDynaset)
-
-
With rsttblAECarAuctionDisposals
-
.AddNew
-
![Registration] = strStringVariable
-
![Tag] = strStringVariable
-
![VAT Status] = strStringVariable
-
![Vehicle Description] = strStringVariable
-
![Buyer] = strStringVariable
-
![Date Sold] = dteDateVariable
-
![Sale Price (Gross)] = curCurrencyVariable
-
![VAT] = curCurrencyVariable
-
![Net Proceeds] = curCurrencyVariable
-
![Mileage] = lngLongVariable
-
![Year/Letter] = strStringVariable
-
.Update
-
End With
-
-
-
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?
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! ^_^
Ok, thanks. How do I get the button to open a pop up form for them to enter a new record?
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! ^_^
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....
DoCmd.GoToRecord , , acNewRec
DoCmd.GoToRecord , , acNewRec
That's what I wanted - thanks!! Realise it's crude, but it does what I need.
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! ^_^
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!!
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
|
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
|
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...
| |