Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-09-29
5
Medium Priority
?
444 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 2000 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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

An introduction to the wonderful sport of Scam Baiting.  Learn how to help fight scammers by beating them at their own game. This great pass time helps the world, while providing an endless source of entertainment. Enjoy!
This article outlines the struggles that Macs encounter in Windows-dominated workplace environments – and what Mac users can do to improve their network connectivity and remain productive.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

661 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