Split Form (no autonumber)

dcc15

New member
Local time
Today, 15:54
Joined
Nov 26, 2007
Messages
9
Hi, This is my first post here.
I'd like to say that I'm new to VBA and am learning.
I have a text value (letters and numbers) that is my primary key (be nice) and I am having trouble switching from one form to another (same table). I know it has something to do with querying the record when Form2 opens (want Form1 to close when Form2 opens). I am stuck with this ID format so please don't slam me. I am able to do this when I add a "autonumber" to the table and use it in the forms. As I will have this ID in the table anyway and it will be unique to each record and will be used to relate several tables I hate to stick an autonumber in just to be able to do this. Below is the code I am currently using with the autonumber, any help would be appreciated.
Thanks, DCC

Form1:
Private Sub cmdContinueReport_Click()
On Error GoTo MyErrorHandler

Me.mycheckbox = True

Dim lngID As Long
lngID = Me.ID 'Autonumber, would like to use text value
DoCmd.Close acForm, Me.Name
DoCmd.OpenForm "FORM2", , , "ID = " & lngID

MyErrorHandlerExit:
Exit Sub
MyErrorHandler:
MsgBox "Error Description: " & Err.Description & " Error Number: " & Err.Number
Resume MyErrorHandlerExit

End Sub
 
Change it to this:

Dim strID As String
strID = Me.ID
DoCmd.Close acForm, Me.Name
DoCmd.OpenForm "FORM2", , , "[ID]= '" & strID & "'"
 
Solved, Thanks (those darn quotes)

I knew it was those quote marks, I'm still trying to figure out how/when to use them. I tried this (a few times) just couldn't get the quotes right.
Thanks alot, any suggestions on good material about those darn quotes single/double, anyway thanks again!
DCC
 
Okay, here's a short tutorial:

1. When you are passing a string to something (and the where clause of the form open command is passing a string) you need the double quotes on the beginning and end of the string.
2. When you are referencing a control on a form, or a variable, it needs to be outside of the quotes. So, therefore you would encapsulate everything up to that point and use an ampersand (&) to concatenate the two strings on either side of the control, or variable, reference.
3. Use single quotes within a string that has double quotes around it.
4. When looking for numbers, no single quotes are neccesary.
5. When looking for TEXT you would use the single quotes like we did in your example.
6. When looking for DATES you would use this sign # in place of the single quotes.

Hopefully that helps.
 
Short Tutorial- Thanks

I actually understood that, thanks for the explanation.
DCC
 

Users who are viewing this thread

Back
Top Bottom