Image of Navigational Panel mapped to Contents / Home / Search "Invalid argument" Error
Tech Support Question

Image of Line Break

Q. Hey guys. OK - here's my problem. First, I'm using VB 3.0 Pro. When trying to create a new database from code, I keep getting an "Invalid argument" error. Here's the code I'm using...

  testname$ = InputBox$("What do you want to name your test?")
  Dim db As Database
  Dim dbname As String
  dbname$ = CurDir$ + "\" + testname$
  Set db = CreateDatabase(dbname$, DB_LANG_GENERAL, DB_VERSION10)

Now, this is pretty much straight out of the book, and it's on the last line that I'm getting hung. Any ideas?

Thanks in advance...
From: Tom Davidson (Apache)
Email: Apache@Cupid.com

A. Tom, I'm not sure why your code is not working. I have executed the same code under VB3 and it works just fine. However, I have also played around with the code a little and have found only one way to generate the "Invalid argument" error. The second parameter (DB_LANG_GENERAL) must be a string and must contain a number of obscure settings. In fact the value you are looking for is ";LANGID=0x0809;CP=1252;COUNTRY=0". If you try to pass in a string which does not have contents resembling these you are headed for trouble. You can find the definition of this value in DATACONS.TXT which you will find in you VB directory.

I suspect what is actually happening is that you do not have Option Explicit set on (have a look at 'Require Variable Declaration' in Options|Environment) which means that VB will let you get away with referencing variables that you have not declared and will simply create them as needed. If you do not have DB_LANG_GENERAL declared VB will create the variable as a variant with a default string value of "". As far as JET is concerned this is not a valid set of settings and there you have the "invalid argument" error.

Do yourself a favour and avoid troubles like this in the future by setting Option Explicit on. Then make sure that the declaration for DB_LANG_GENERAL is included in your project (you may wish to add DATACONS.TXT to your project). You should then find that the code will run without a problem.

By the way, you may wish to consider removing the last parameter so that you produce a Version 1.1 database instead of a version 1.0 database. If you download a file called comlyr.exe (725 KB) this will allow you to produce Version 2.0 databases by default.

Enjoy.


Image of Arrow to Previous Article Image of Arrow to Next Article

[TECH SUPPORT TOC]
Image of Line Break
[HOME] [TABLE OF CONTENTS] [SEARCH]