ianohlander
New Member
- Joined
- Dec 5, 2002
- Messages
- 26
Hey again,
2 questions:
A general sort:
I have a number of SQL statements that I need to execute from a VBA subroutine. I have 3 tables: customerTable, roomTable, and ReservationTable. customerTable has numerous fields, including customerIDNumber as key. reservationTable has numerous fields, including reservationIDNumber (as key), customerIDNumber, and roomIDNumber. Finally, roomTable has numerous fields including roomIDNumber and reservationIDNumber (the last is for checking availability- if it contains the default -1, then it is free).
Now, I have to to basically accomplish this:
So I have a two-part question:
1) should I use a transaction to do this (and how)?
2) since the *IDNumber's are auto-generated by access, how do I get (and hold) their ID numbers without another requery after their creation?
I have been leaning toward the AS keyword (it can be used a variable in a transaction, right?) and am trying out the "transaction" block. But both are giving me errors in Excel. Can it be done in excel?
If it can't, I'm really not sure how to proceed, except to (redundantly) retrieve the room through 1 query, store the ID in a variable. Then create a customer. Then query for that customer so I can access/store it's ID. Then create a reservation and then query it so I can access/store it's ID. Finally, using 2 final sql statements, make the appropriate updates in reservationTable and roomTable.
But that would be 7 DB queryies/updates- and that seems riduculously complicated, inefficient, and in fact a drain on resources.
So what would be the best way to do that?
Specific question:
I have been a problem with using an INSERT SQL statement in a VBA sub. Excel is being used as a frontend to an access db (long story short- the customer wanted it to be in excel, even though it really should have been done in Access and used OLE to create the spreadsheets.)
Here's the SQL code that is being created:
But I keep getting a "runtime error- syntax error in INSERT INTO statement"
Yet the SQL INSERT statement follows both the general signature and also examples that I have in my SQL books.
I tried adding a ';' at the end (like an access query SQL). Still no dice.
The code generating this is:
What am I doing wrong?
This makes no sense.
Thanks for your help,
Ian Ohlander
ianohlander@yahoo.com
2 questions:
A general sort:
I have a number of SQL statements that I need to execute from a VBA subroutine. I have 3 tables: customerTable, roomTable, and ReservationTable. customerTable has numerous fields, including customerIDNumber as key. reservationTable has numerous fields, including reservationIDNumber (as key), customerIDNumber, and roomIDNumber. Finally, roomTable has numerous fields including roomIDNumber and reservationIDNumber (the last is for checking availability- if it contains the default -1, then it is free).
Now, I have to to basically accomplish this:
- get a room from roomTable (of particular type and number)
- create a customer in customerTable
- create a reservation in reservationTable, and set it's customerIDNumber to that of the new customer, and it's roomIDNumber to that of the retrieved room.
- Finally, set the retrieved room's reservationIDNumber to the new reservation's ID number.
So I have a two-part question:
1) should I use a transaction to do this (and how)?
2) since the *IDNumber's are auto-generated by access, how do I get (and hold) their ID numbers without another requery after their creation?
I have been leaning toward the AS keyword (it can be used a variable in a transaction, right?) and am trying out the "transaction" block. But both are giving me errors in Excel. Can it be done in excel?
If it can't, I'm really not sure how to proceed, except to (redundantly) retrieve the room through 1 query, store the ID in a variable. Then create a customer. Then query for that customer so I can access/store it's ID. Then create a reservation and then query it so I can access/store it's ID. Finally, using 2 final sql statements, make the appropriate updates in reservationTable and roomTable.
But that would be 7 DB queryies/updates- and that seems riduculously complicated, inefficient, and in fact a drain on resources.
So what would be the best way to do that?
Specific question:
I have been a problem with using an INSERT SQL statement in a VBA sub. Excel is being used as a frontend to an access db (long story short- the customer wanted it to be in excel, even though it really should have been done in Access and used OLE to create the spreadsheets.)
Here's the SQL code that is being created:
Code:
INSERT INTO yearTable(year, startDate, endDate, currentYear) Values('2076', 'June 29', 'July 18', true)
But I keep getting a "runtime error- syntax error in INSERT INTO statement"
Yet the SQL INSERT statement follows both the general signature and also examples that I have in my SQL books.
I tried adding a ';' at the end (like an access query SQL). Still no dice.
The code generating this is:
Code:
'after code using inputBoxes to get the referred-to-below variables.
dim conn As ADODB.Connection
dbName = ThisWorkbook.Path & "globexlDB.mdb"
Set conn = New ADODB.Connection
conn.Open ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & dbName & ";")
createNewYearSQL = "INSERT INTO yearTable(year, startDate, endDate, currentYear)" & _
" VALUES('" & newYearYear & "', '" & newYearStart & "', '" & newYearEnd & _
"', true)"
MsgBox (createNewYearSQL)
conn.Execute (createNewYearSQL)
What am I doing wrong?
This makes no sense.
Thanks for your help,
Ian Ohlander
ianohlander@yahoo.com