-----Original Message-----
Yes, AppCode is the so called random number that we are
seeking. Date is the date of the request, MM/DD/YYYY. Our
Microsoft Press books use the name Date, so that is news
to us. But ReqDate will work, if you like. EmpName is the
name of the employee requesting the code acquired via
drop down in the format: Smith, John. This data is
entered into a simple data-entry form that obviously
feeds Table1. This data will be entered by a Supervisor
for an employee requesting approval. And as mentioned
prior to, approvals are almost never done more than once
a day for an employee, so the re-occurrence of a random
number for that person on that date won't be an issue.
Right: so it sounds like you need a command like this:
INSERT INTO Table1 (AppCode, ReqDate, EmpName)
VALUES( 12345, #2003-06-12#, "Eric");
and notice how all the different data types are delimited properly[1]. Now,
to make up this string, it's just a question of taking things bit by bit.
First of all get the values -- I don't know where these come from, but I
really don't need to, as long as you do.
Dim dwAppCode as long
Dim dtReqDate as date
Dim strEmpName as String
dwAppCode = GetNewRandomFiveDigitNumberFromSomewhere()
dtReqDate = LookUpRequestDateFromRequestLog()
strEmpName = SecurityObject.CurrentEmpName
and put the actual command together. Once again, make sure that the
different data types are formatted and delimited properly
Dim strSQL as string
strSQL = "INSERT INTO Table1 (AppCode, ReqDate, EmpName) & _
vbNewLine
' numbers don't need anything special, but this will catch
' an illegally big number > five digits
strSQL = strSQL & "VALUES (" & Format (dwAppCode,"00000") & ", "
' dates have to have # chars round and must be in a jet-
' compatible format. I prefer the ISO standard
strSQL = strSQL & Format(dtReqDate, "\#yyyy\-mm\-dd\#) & ", "
' strings have double quotes - if you are using SQL Server then
' they must be single quotes instead. Make sure you don't have
' any quote marks inside the EmpName. Anything like O'Neill or
' Gerry "the keyboard" Marks will cause problems.
strsQL = strSQL & Chr$(34) & strEmpName & Chr$(34) & ");"
and then make sure it looks right: remove this line once it is all working
properly
MsgBox strSQL
and if everything looks okay you are set to go:
Dim db as DAO.Database
Set db = CurrentDB()
db.Execute strSQL, dbFailOnError
By the way, the last post was not done by myself.
Apols, in that case. I don't know where all these anonymous postings have
come from but I do wish they would go away as it is completely rupturing
any kind of continuity in these threads :-(
Hope that helps
Tim F
.