SachAccess
Active member
- Local time
- Today, 18:15
- Joined
- Nov 22, 2021
- Messages
- 389
Hi,
I am getting bug while trying to run below code in my FORM. Please note that I have changed names of Tables and Fields due to security reasons.
Task I am trying to achieve is get the maximum number of a field from the table.
Tbl_Vendor_Details has a column for Location_Id.
Location_Id are numbers.
Region_Id is field from Tbl_Vendor_Details.
Location_Id is different for each Region_Id.
Form_Frm_Dashboard.Cmb_Region.Value is showing correctly in the code (checked in IM window).
However am getting error at 'Set rs = DB.OpenRecordset(SqlStr, dbOpenDynaset)' this line.
Can anyone please help me in this. Thanks.
I am getting bug while trying to run below code in my FORM. Please note that I have changed names of Tables and Fields due to security reasons.
Task I am trying to achieve is get the maximum number of a field from the table.
Tbl_Vendor_Details has a column for Location_Id.
Location_Id are numbers.
Region_Id is field from Tbl_Vendor_Details.
Location_Id is different for each Region_Id.
Form_Frm_Dashboard.Cmb_Region.Value is showing correctly in the code (checked in IM window).
However am getting error at 'Set rs = DB.OpenRecordset(SqlStr, dbOpenDynaset)' this line.
Can anyone please help me in this. Thanks.
Code:
Private Sub Form_Load()
Me.cmb_Recorded_By.Enabled = True
Me.cmb_Recorded_By.SetFocus
Me.cmb_Recorded_By.Text = Environ("UserName")
Me.cmb_Recorded_By.Enabled = False
Me.Cmb_Region_ID.Value = Form_Frm_Dashboard.Cmb_Region.Value
If IsNull(Me.Tbx_Vendor_Id.Value) Then
SqlStr = "Select max(Vendor_Id) as PrdId from Tbl_Vendor_Details Where Region_Id = " & Form_Frm_Dashboard.Cmb_Region.Value
Set rs = DB.OpenRecordset(SqlStr, dbOpenDynaset)
If IsNull(rs!PrdID) Then
NewID = 1
Else
NewID = rs!PrdID + 1
End If
rs.AddNew
Else
msg = MsgBox("Do you want to update the record?", vbYesNo + vbExclamation, "Please Specify :")
If msg = vbNo Then rs.Close: Exit Sub
rs.Close
SqlStr = "Select * from Tbl_Vendor_Details where Vendor_Id = " & Me.Tbx_Vendor_Id.Value & ";"
'SqlStr = "Select * from Tbl_Product_Category where Product_Category_Id = " & Me.Tbx_Product_Category_Id.Value & ";"
Set rs = DB.OpenRecordset(SqlStr, dbOpenDynaset)
rs.Edit
End If
End Sub