O
osmondb
Hi all,
I'm extremely new to VB, let alone VB with Access. I
started off by trying to create a query that would "loop"
(repeat) but I was told that it was better to include the
SQL code into the VBA code.
First off, I have a table with three fields...a Type (A, B,
or C), then a reference number for each record, and a
true/false field. I want to be able to run the module and
it asks "which type of records would you like to update, a
b or c ...) and then once this is selected, you just keep
entering the reference numbers for each record and the
true/false field is automatically set to True. The code I
have so far is:
-------------------------------------------
Public Sub RunQueryUntilDone()
Dim strSQL As String
Dim dbs As DAO.Database
Dim strID As String
Set dbs = CurrentDb
strID = "starting"
strID = InputBox("Enter Type of Records You Want To
Update (A, B, or C):")
If strID <> "" Then
strSQL = "SELECT TypeIdBool.FieldOne,
TypeIdBool.FieldTwo, TypeIdBool.FieldThree" & _
"FROM TypeIdBool" & _
"WHERE (((TypeIdBool.FieldOne)=))" &
CLng(strID) & ";"
dbs.Execute strSQL, dbFailOnError
Else
MsgBox "No value entered. Query ending now."
End If
Do
strID = InputBox("Enter Record ID or enter nothing
to stop:")
If strID <> "" Then
strSQL = "UPDATE TypeIdBool SET FieldThree =
True " & _
"WHERE [FieldTwo]=" & CLng(strID) & ";"
dbs.Execute strSQL, dbFailOnError
Else
MsgBox "No value entered. Query ending now."
Exit Do
End If
Loop
dbs.Close
Set dbs = Nothing
End Sub
-------------------------------------------
As I said, I'm extremely new to VB...most of this code was
generated by an MVP on another newsgroup, I just edited it
and tailored it to suit my database. TypeIdBool is the
table name, FieldOne is the record type (a, b or c),
FieldTwo is the record number, and FieldThree is the
true/false field. Whenever I run the database, I'm getting
an error on Line 10 (first strSQL) that says Run-Time Error
13, Type Mismatch and I have no idea how to get this code
to run =\ . Any and all help/input is appreciated! Thanks
a bunch!
OsmondB
I'm extremely new to VB, let alone VB with Access. I
started off by trying to create a query that would "loop"
(repeat) but I was told that it was better to include the
SQL code into the VBA code.
First off, I have a table with three fields...a Type (A, B,
or C), then a reference number for each record, and a
true/false field. I want to be able to run the module and
it asks "which type of records would you like to update, a
b or c ...) and then once this is selected, you just keep
entering the reference numbers for each record and the
true/false field is automatically set to True. The code I
have so far is:
-------------------------------------------
Public Sub RunQueryUntilDone()
Dim strSQL As String
Dim dbs As DAO.Database
Dim strID As String
Set dbs = CurrentDb
strID = "starting"
strID = InputBox("Enter Type of Records You Want To
Update (A, B, or C):")
If strID <> "" Then
strSQL = "SELECT TypeIdBool.FieldOne,
TypeIdBool.FieldTwo, TypeIdBool.FieldThree" & _
"FROM TypeIdBool" & _
"WHERE (((TypeIdBool.FieldOne)=))" &
CLng(strID) & ";"
dbs.Execute strSQL, dbFailOnError
Else
MsgBox "No value entered. Query ending now."
End If
Do
strID = InputBox("Enter Record ID or enter nothing
to stop:")
If strID <> "" Then
strSQL = "UPDATE TypeIdBool SET FieldThree =
True " & _
"WHERE [FieldTwo]=" & CLng(strID) & ";"
dbs.Execute strSQL, dbFailOnError
Else
MsgBox "No value entered. Query ending now."
Exit Do
End If
Loop
dbs.Close
Set dbs = Nothing
End Sub
-------------------------------------------
As I said, I'm extremely new to VB...most of this code was
generated by an MVP on another newsgroup, I just edited it
and tailored it to suit my database. TypeIdBool is the
table name, FieldOne is the record type (a, b or c),
FieldTwo is the record number, and FieldThree is the
true/false field. Whenever I run the database, I'm getting
an error on Line 10 (first strSQL) that says Run-Time Error
13, Type Mismatch and I have no idea how to get this code
to run =\ . Any and all help/input is appreciated! Thanks
a bunch!
OsmondB