 |
| Access VBA Discuss using VBA for Access programming. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

December 21st, 2006, 03:05 PM
|
|
Authorized User
|
|
Join Date: Aug 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Help with underscore
Hello,
I'm still learning my VBA and having some success with it. I'm having problem with one line of code where I want it to insert an underscore and it's throwing me. My line of code is:
Code:
rst("School" & "_" & "Program" & "_" & "Course_Code") = [CourseID]
Obviously using "_" isn't the right way to code it. Could someone help me out.
Thanks in advance,
Arholly
|
|

December 22nd, 2006, 08:04 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
Try this:
Dim sSPCC As String
sSPCC = "School" & "_" & "Program" & "_" & "Course_Code"
rst(sSPCC) = [CourseID]
HTH
mmcdonal
|
|

December 22nd, 2006, 08:04 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
Actually, what am I saying? Do this:
sSPCC = "School_Program_Course_Code"
mmcdonal
|
|

December 22nd, 2006, 09:44 AM
|
|
Authorized User
|
|
Join Date: Aug 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
It's tossing an error on this line:
rst(sSPCC) = [CourseID]
Now, I'm wondering. Is it throwing an error because [Course_Code] has an underscore as well?
|
|

December 22nd, 2006, 10:09 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
Yeesh, am I not thinking this morning or what?
Do this:
sSPCC = Me.CourseID
rst("School_Program_Course_Code") = sSPCC
This is if you are taking a value OFF a form and passing it to the recordset for an update or insert.
mmcdonal
|
|

December 22nd, 2006, 10:21 AM
|
|
Authorized User
|
|
Join Date: Aug 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I'm not. I'm creating the CourseID from the Schoool/Program/Course_Code. Because they are unique, they then become the PK.
|
|

December 22nd, 2006, 11:28 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
Oooooh, I thought you wanted help with a regular expression. Yeesh! <smacking forehead>
Okay, do this:
sSPCC = Me.School & "_" & Me.Program & "_" & Me.COurseCode
Then
rst("PKFieldName?") = sSPCC
mmcdonal
|
|

December 22nd, 2006, 12:19 PM
|
|
Authorized User
|
|
Join Date: Aug 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Okay, when I make the code like follows, it keeps throwing an error on Me.Program, saying method or data member not found.
Code:
Private Sub Command31_Click()
Dim sSPCC As String
Set db = CurrentDb()
Set rst = db.OpenRecordset("tbl_Courses", dbOpenDynaset)
sSPCC = Me.School & "_" & Me.Program & "_" & Me.CourseCode
rst.AddNew
rst("School") = [School]
rst("Program") = [Program]
rst("Course_Code") = [Course_Code]
rst("Course_Description") = [Course_Description]
rst("ISBN") = sSPCC
rst.Update
rst.Close
MsgBox ("Course Added.")
[School] = Null
[Program] = Null
[Course_Code] = Null
[Course_Description] = Null
End Sub
|
|

December 26th, 2006, 10:39 AM
|
|
Authorized User
|
|
Join Date: Dec 2006
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Everything looks right here from where I look. You may want to check your Me.Program object to make sure the name is correct.
Also, the name "program" may be a special phrase. Try renaming your object to something else.
--------------------------------
Ben
"It's my way, or the Hemingway."
--------------------------------
|
|
 |