I'm using a code to transfer data from a user form in excel to an access data base.
with rs
.addnew
.field ("status") =combobox1.value
All data tranfers when an entry is made in the combo/text box however a user may leave them blank. This then throws up a runtime error, can anybody help please.
Regards
nominoo
3 2527
Hi Nominoo, and Welcome to Bytes!
What run-time error are you getting? Is it an Excel run-time error or an Access one?
It could be that your Access table's Status field is set not to allow null values (values which indicate that an entry has not been made yet). If this was the case, you could try using the Nz function to return a non-null value to your Status field. If Status is a text field (you don't say what type it is) then you could use Nz as follows: - .field("status") = Nz(Combobox1)
(The .value property does not normally have to be stated explicitly, as it is the default property returned when you refer to a control.)
If your Status field is a number, then Nz can be used to return 0 if a null is encountered. like this: - .field("status") = Nz(Combobox1, 0)
If it turns out that the null value in your combo box is not the issue here it would really help to know what the run-time error code and text is and which application is reporting it.
-Stewart
Hi Stweart
Thanks for reply, I am really new to doing this kind of thing and I'm really struggling at the mo.
I have set up a user form in excel, which has a number of combo boxes and textboxes which allows a user to input data. Some of the text boxes link to formulas in cells on the spreadsheet and show there values(it has just dawned on me that this maybe the problem).
The user doesn't have to complete all of the boxes so there maybe combo boxes text boxes left blank.
I then have a command button which is pressed to submit the data to an access database. If all combo boxes and textboxes have an entry in them the data is tranferred no problems, however if they don't have an entry I am receiving this error.
run-time error '-2147352571 (80020005)' type mis match (in excel)
Here is a condensed version it:
Private Sub CommandButton2_Click()
Dim cn As ADODB.Connection, rs As ADODB.Recordset
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=\filepath.mdb"
Set rs = New ADODB.Recordset
rs.Open "Main", cn, adOpenKeyset, adLockOptimistic
With rs
.AddNew
.Fields("Status") = ComboBox1.Value
.Fields("RRR") = ComboBox46.Value
.Fields("RRS") = ComboBox52.Value
.Fields("SRR") = ComboBox47.Value
.Fields("SRS") = ComboBox53.Value
.Fields("WSR") = ComboBox48.Value
.Fields("WSS") = ComboBox108.Value
.Fields("WPR") = ComboBox110.Value
.Fields("WPS") = ComboBox112.Value
.Fields("WER") = ComboBox49.Value
.Fields("WES") = ComboBox54.Value
.Update
End With
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
MsgBox ("Your data has been sent")
UserForm_Initialize
End Sub
I'd certainly try the Nz approach to see if this resolves the problem.
You would also benefit from setting a break point at your .Addnew statement and stepping through one line at a time to see if it fails at one particular blank combo, and to be able to test values using the immediate window.
There is an introductory article (one of a series) in our Insights section entitled Debugging in VBA which I have linked here for you, as you may well find it useful to know how to perform simple debugging steps.
-Stewart
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Debaser |
last post by:
Okay, I'm one error away from making this work. Here's my main():
int main(void)
{
size_t x;
long y;
long samples = { 10, 50, 100, 500, 1000, 5000, 10000, 50000,
100000, 500000, 1000000 };
...
|
by: Chris K. |
last post by:
Hi,
Setting my first steps into Java, managing my genealogy website.
In the list of names, with the names in anchor tags,
i want a popup window to appear on clicking the name.
With the command...
|
by: JGBNS via DotNetMonster.com |
last post by:
Hi,
I am new to this forumand I apologize as i am not a .net programmer but we
have a program being developed by a .net programmer. Nowwe have run into an
ftp snag and I think it is part ftp and...
|
by: Paul T. RONG |
last post by:
Hello,
I am making a restaurant database (it is much more complicated than I
thought before!), now it comes to the last stage and I come across a
problem. I will explain it in detail. In a...
|
by: vamsikrishna_b |
last post by:
Hello all,the following problem i encountered while transferring
data(mail ids) from MS-outlook to one application.Some mail ids after
came into the application looked as strange characters.Eg are...
|
by: http://www.visual-basic-data-mining.net/forum |
last post by:
Does anyone have any idea how to transferring data from TextBox1 in form1 to
textBox2 in form2.....
That means after i fill in any data in textBox1 and click Next button...
It will bring me to...
|
by: jayantadutta |
last post by:
hi
i'm facing a problem while transferring date from csv to database.
my quary as follows
if (! firstdate.trim().equals("")) {
System.out.println("insertInToDatabase startdate...
|
by: cloh |
last post by:
I have a form in Access that generates an Excel Workbook with multiple worksheets. Each worksheet is unique to a particular location. The top row of each sheet shows the dates, the left-most column...
|
by: janetopps |
last post by:
I have a news website, with asp pages, which was on Access, and i upgraded to MySQL, i used Bullzip to transfer the data. It had about 1000 pages, which im now able to pull up on the public side. Im...
|
by: angusfreefa |
last post by:
Dear All,
I am facing a problem of transferring data between 2 tables within the same database.
I set up 2 tables. The first table is the permanent table (oos_table) for saving records. the...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |