Thanks. Now I get an error that access can't find the variable strMailbox. I
have it defined, not sure what it is complaining about now. Here is the code
I have:
Private Sub Command1_Click()
Dim dbsSecurity As Database
'Dim rstTechSecurity As Recordset
Dim intTechcode As Integer
Dim strMailbox As String
Dim strSQL As String
Dim FileNumber As Integer
Dim sFile As String
Dim strLine As String
Dim MyPos
Set dbsSecurity = OpenDatabase("Security.mdb")
FileNumber = FreeFile
Open "C:\mailboxestest.txt" For Input As #FileNumber 'open the file
intTechcode = 1
Do Until EOF(FileNumber) 'loop through each line in the file
Line Input #FileNumber, strLine 'store the line as a variable
MyPos = InStr(1, strLine, ",", 1)
If MyPos = 3 Then
intTechcode = Val(Left(strLine, 2))
ElseIf MyPos = 4 Then
intTechcode = Val(Left(strLine, 3))
Else
intTechcode = Val(Left(strLine, 4))
End If
strMailbox = Mid([strLine], MyPos + 1, Len(strLine) - MyPos)
strSQL = "UPDATE TechSecurity SET Mailbox = " &
Forms!AddMailboxes!strMailbox & "WHERE Techcode = " &
Forms!AddMailboxes!intTechcode
dbsSecurity.Execute strSQL
Loop
End Sub
The field techcode is a number and the variable is an integer. What do I
have to do to handle that? strMailbox is a string and the field is also a
string.
Thanks.
dymondjack said:
The Execute method will not call on access expression service (ES gets the
values from expressions like Forms!... or Me.ctlWhatever).
You probably want to build an SQL string first, inserting the actual values,
and then execute the completed statement. Be careful of quotes when building
an SQL string.
Dim strSQL As String
strSQL = "UPDATE TechSecurity SET Mailbox = " &
Forms!AddMailboxes!strMailbox _
& "WHERE Techcode = " & Forms!AddMailboxes!intTechcode
dbsSecurity.Execute strSQL
hth
--
Jack Leach
www.tristatemachine.com
- "Success is the ability to go from one failure to another with no loss of
enthusiasm." - Sir Winston Churchill
:
I am trying to update a table. I have this statement:
dbsSecurity.Execute "UPDATE TechSecurity SET Mailbox =
Forms!AddMailboxes!strMailbox WHERE Techcode = Forms!AddMailboxes!intTechcode"
but I get this error: Runtime error 3061 too few paramters expected 2
what is wrong with the statement?
Thanks!