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
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