Solved

How to transfer a null value on a form to a table

Posted on 2011-09-29
5
437 Views
Last Modified: 2013-11-08
I have produced a database which will allow people to add customer records, edit the data on a form, then trasfer the data into the table, but if the text boxes on the form are left blank , it doesn’t work! How can I get it to work if the value in the text boxes are null??? Please help
This is a sample of my code:

Private Sub btaddtotable_Click()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim varTextDataA As String
Dim vartextdataB As String
Dim vartextdataC As String
Dim vartextdataD As String
Dim vartextdataE As String
Dim vartextdataF As String

varTextDataA = srn
vartextdataB = invoice2
vartextdataC = BuyerName2
vartextdataD = BuyerAdd1
vartextdataE = BuyerAdd2
vartextdataF = BuyerAdd3

Set db = CurrentDb
Set rst = db.OpenRecordset("UK Sales", dbOpenDynaset)

    rst.AddNew
        rst!SalesRecordNumber = varTextDataA
        rst!InvoiceDate = vartextdataB
        rst!BuyerFullName = vartextdataC
        rst!BuyerAddress1 = vartextdataD
        rst!BuyerAddress2 = vartextdataE
        rst!BuyerAddress3 = vartextdataF


0
Comment
Question by:ridgejason
  • 3
5 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 36814695
For anything that allows Nulls, declare them as Variant not String.
0
 
LVL 8

Expert Comment

by:jawa29
ID: 36814704
Hi

You need to allow null entries on the database columns affected.

In SQL this is done in Design View there's a tick at the end of each column that says Allow Nulls.

Jawa29
0
 
LVL 61

Expert Comment

by:mbizup
ID: 36814728
ie:

>> Dim varTextDataA As String

Should be:
Dim vartextdataB As Variant

Also, this intermediate step is unnecessary:

varTextDataA = srn
vartextdataB = invoice2
vartextdataC = BuyerName2
vartextdataD = BuyerAdd1
vartextdataE = BuyerAdd2
vartextdataF = BuyerAdd3

Open in new window


You can set the fields directly from the textboxes:

rst!SalesRecordNumber= srn
  rst!InvoiceDate = invoice2

etc.

With the latter method, nulls are not an issue - as long as the underlying field allows nulls

0
 

Author Comment

by:ridgejason
ID: 36814776
Thank you, I knew it would be something simple.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 36814984
Glad to help out.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now