Can I use the autonumber ID which is my primary key to open a form based on a record?
I have a new database set up to:
- select a record from a continuous form
- click a button (called "Open Material Record") to open a form based on that record
- pass the variable as an open argument
- use the open argument to set a query string for the recordsource
The number passed as my open argument is correct, but when I do (step 4) I get a type error: "run-time error '3464': Data type mismatch in criteria expression"
Here's my code:
On the Open Material Record button:
Code:
Private Sub Mat_Open_Button_Click() Dim idNumber As String
idNumber = Me!ID_NUMBER ' this is a control on the continuous form that displays the ID
'DoCmd.Close acForm, "Landing_Page"
DoCmd.OpenForm "RAM_Form", OpenArgs:=idNumber
End Sub
On the edit record form:
Code:
Private Sub Form_Open(Cancel As Integer)
If Nz(Me.OpenArgs) = 0 Then
Me.RecordSource = "WASTE_INVENTORY"
DoCmd.RunCommand acCmdRecordsGoToNew
Else
Me.RecordSource = "Select WASTE_INVENTORY.* FROM WASTE_INVENTORY WHERE (((WASTE_INVENTORY.ID)='" & Me.OpenArgs & "'));"
End If
end sub
It is not pictured above, but I have tried setting a variable to me.openargs and then type converting to variant or integer using CVar and CInt, but they are just the wrong variable types.
I would normally use a unique identifier as a SK, but the field that I would use for that is blank on two records from the import. I guess I could just put a number in there, but I'd like to make it work this way if possible.