Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Append Global Variables and Textbox Values to a table 1

Status
Not open for further replies.

jcw5107

Technical User
Jan 31, 2007
66
0
0
US
I have a bit of code that I am working with that works with the items selected in a listbox. From there, I would like to add new part#s based on the items selected. This way I can assign 1 part# to several Task#s (if several are selected) at one time....
I am having "syntax" problems with the append query I'm tryin' to run... Not sure if I need to use "SELECT" or "VALUES" or both..??? I'm tryin' to INSERT from a table, a few Global Variables, and a few textboxes on my form...Below is what I am working with:

DoCmd.RunSQL "INSERT INTO PartMaster ( TaskNo, FleetID, DocNo, MPN, IID, Qty, Unit, TotReqd) " & _
"SELECT TaskMaster.TaskNo, " & GBLFleetID & "," & GBLDocNo & "," & Me.MPNLookup & "," & Me.IIDLookup & "," & Me.txtQty & "," & Me.txtUnit & "," & Me.txtTotalReqd & " " & _
"FROM TaskMaster " & _
"WHERE (((IsSelectedVar('Documents','TaskNoList',[TaskNo]))=-1));"

TaskNo - number data type
FleetID - text data type
DocNo - text data type
MPN - text data type
IID - text data type
Qty - number data type
Unit - text data type
TotReqd - text data type

Any fixes, suggestions, examples...??
Thanks in advance..!!
jcw5107
 

Text data types need to be surounded be single quotes.

"INSERT INTO PartMaster ( TaskNo, FleetID, DocNo, MPN, IID, Qty, Unit, TotReqd) " & _
"SELECT TaskMaster.TaskNo, '" & GBLFleetID & "', '" & GBLDocNo & "', '" & ......

Dates on the other hand need the #

BTW Is this (((IsSelectedVar('Documents','TaskNoList',[TaskNo]))=-1)) a function to filter TaskMaster table ? An INNER JOIN wouldn't be of help?
 
JerryKlmns,

That was it...!!
Again, if it was a snake - it would have bit me...!!
It was right in front of me this whole time...!!
Thanks for you help...

The " (((IsSelectedVar('Documents','TaskNoList',[TaskNo]))=-1)) " part of the query comes from another piece of code from a sample database I got a hold of... I think Dhookum created this, which is awesome...!! It allows the user to select multiple items from a listbox, and view all that was selected via a query....

In a Module:
Function IsSelectedVar( _
strFormName As String, _
strListBoxName As String, _
varValue As Variant) _
As Boolean
'strFormName is the name of the form
'strListBoxName is the name of the listbox
'varValue is the field to check against the listbox
Dim lbo As ListBox
Dim item As Variant
If IsNumeric(varValue) Then
varValue = Trim(Str(varValue))
End If
Set lbo = Forms(strFormName)(strListBoxName)
For Each item In lbo.ItemsSelected
If lbo.ItemData(item) = varValue Then
IsSelectedVar = True
Exit Function
End If
Next
End Function

SQL:
SELECT Employees.*
FROM Employees
WHERE IsSelectedVar("frmMultiselectListDemo","lboEmployeeID",[EmployeeID])=-1;

 
jcw5107

Glad to be of help and ... thanx for that piece of code I've missed.

Geee. I've got to stay tuned all the time 'cause TT commynity never cease to amaze me!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top