Help in assigning bitmap value

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

I have to assign the bitmap value to a event. The folowing is the global
code construct for that event:

Public Const AllBits = &HFFFFFFFF
Public Const cvPillar = &H1 '2 to the zero
Public Const cvCategory = &H2 '2 to the one
Public Const cvProjectTitle = &H4 '2 to the second
Public Const cvOrigResearchLocation = &H8 '2 to the third
Public Const cvInstitutionPaid = &H16 '2 to the forth
Public Const cvHealthAuthority = &H32 '2 to the fifth
Public Const cvUniversityAffiliation = &H64 '2 to the sixth
Public Const cvRecruitmentStatus = &H128 '2 to the seventh
Public Const cvFundingStatus = &H256 '2 to the eigth
Public Const cvDeclined = &H512 '2 to the ninth
Public Const cvFundingAgency = &H1024 '2 to the tenth
Public Const cvFundingType = &H2048 '2 to the eleven
Public Const cvFundingAmount = &H4096 '2 to the twelve
Public Const cvStartDate = &H8192 '2 to the thirteen
Public Const cvEndDate = &H16384 '2 to the forteen
'next bit is flag to signal end of valid bits
Public Const HighFlag1 = &H32768

In the form I declare the variable as LONG, so that based on the set value
(2 to the power n) from above it will retuen the value like
1,2,4,8,16....512,1024,2048 and so on. Somehow the first 4 values are
correct,1,2,4 and 8. But with the "2 to the fifth" it returned 22, the "2 to
the sixth" returned 50,100,296,598,1298 ....and so on.

Option Compare Database
Option Explicit

' A ChangeVariable is needed for every 31 fields. It holds
' the bitmap for writing to the History Table.
Dim ChangeVariable1 As Long

Private Sub Category_AfterUpdate()
'Check to see if Category has changed from what it was
'when the record was brought in. If it changed, set the
'bit for the Category field. If it hasn't, clear the bit.
If txtCategoryOld <> Category Or IsNull(Category) Then
ChangeVariable1 = ChangeVariable1 Or cvCategory
Else
ChangeVariable1 = ChangeVariable1 And (AllBits - cvCategory)
End If
End Sub

Private Sub Form_AfterUpdate()
If ChangeVariable1 = 0 Then
Exit Sub ' Don't write a record
End If
WriteHistory ' Write a history record
End Sub



Public Sub WriteHistory()
Dim MsgResponse As Integer
MsgResponse = MsgBox("Add a Comment to this history record?", vbYesNo,
"History Routine Message")
If MsgResponse = vbYes Then
DoCmd.OpenForm "Frm_Comments", , , , , acDialog
End If
htrs.AddNew
htrs("ApplicationNumber") = ApplicationNumber
htrs("User") = fOSUserName
htrs("Date") = Now()
htrs("HistoryCode") = HistoryCode
htrs("FieldsUpdated1") = ChangeVariable1
htrs("Comments") = CurrentComments
htrs.Update
htrs.Bookmark = htrs.LastModified
CurrentComments = ""
End Sub

On another form I assign the follow code

Private Sub cmdDetails_Click()
Dim Ckval As Long
Dim Endval As Long
Dim Testval As Long
Dim Fldcount As Integer
Dim FieldList As String
Fldcount = 0
FieldList = ""
Endval = HighFlag1
Testval = [FieldsUpdated1]
Ckval = &H1 'Start at the beginning
Do While (Ckval < Endval)
If (Ckval And Testval) Then
Fldcount = Fldcount + 1
FieldList = FieldList & FillString1(Ckval) & vbCrLf
End If
Ckval = Ckval + Ckval
Loop
If Fldcount = 0 Then
MsgBox "There were no fields changed." & vbCrLf & vbCrLf & "By: " &
[User]
Else
MsgBox "This history was written with the following fields changed:
" _
& vbCrLf & FieldList & vbCrLf & "By: " & [User]
End If
End Sub

Public Function FillString1(Ckval As Long) As String
Select Case Ckval
Case &H1
FillString1 = "Pillar"
Case &H2
FillString1 = "Category"
Case &H4
FillString1 = "ProjeactTitle"
Case &H8
FillString1 = "OrigResearchLocation"
Case &H16
FillString1 = "InstitutionPaid"
Case &H32
FillString1 = "HealthAuthority"
Case &H64
FillString1 = "UniversityAffiliation"
Case &H128
FillString1 = "RecruitmentStatus"
Case &H256
FillString1 = "FundingStatus"
Case &H512
FillString1 = "Declined"
Case &H1024
FillString1 = "FundingAgency"
Case &H2048
FillString1 = "FundingType"
Case &H4096
FillString1 = "FundingAmount"
Case &H8192
FillString1 = "StartDate"
Case &H16384
FillString1 = "EndDate"
End Select

End Function
 
You are trying to specify a Decimal base with a Hex(&H) identifier. Just
remove the "&H". Also add the "&" sign to the end to force an evaluation
to a Long. The VB intrepreter will automatically remove it where it is
not required.

Just to be clear, &H16 evaluates to 22.
1 x 16 + 6= 22
--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.


Paul said:
I have to assign the bitmap value to a event. The folowing is the global
code construct for that event:

Public Const AllBits = &HFFFFFFFF
Public Const cvPillar = &H1 '2 to the zero
Public Const cvCategory = &H2 '2 to the one
Public Const cvProjectTitle = &H4 '2 to the second
Public Const cvOrigResearchLocation = &H8 '2 to the third
Public Const cvInstitutionPaid = &H16 '2 to the forth
Public Const cvHealthAuthority = &H32 '2 to the fifth
Public Const cvUniversityAffiliation = &H64 '2 to the sixth
Public Const cvRecruitmentStatus = &H128 '2 to the seventh
Public Const cvFundingStatus = &H256 '2 to the eigth
Public Const cvDeclined = &H512 '2 to the ninth
Public Const cvFundingAgency = &H1024 '2 to the tenth
Public Const cvFundingType = &H2048 '2 to the eleven
Public Const cvFundingAmount = &H4096 '2 to the twelve
Public Const cvStartDate = &H8192 '2 to the thirteen
Public Const cvEndDate = &H16384 '2 to the forteen
'next bit is flag to signal end of valid bits
Public Const HighFlag1 = &H32768

In the form I declare the variable as LONG, so that based on the set value
(2 to the power n) from above it will retuen the value like
1,2,4,8,16....512,1024,2048 and so on. Somehow the first 4 values are
correct,1,2,4 and 8. But with the "2 to the fifth" it returned 22, the "2 to
the sixth" returned 50,100,296,598,1298 ....and so on.

Option Compare Database
Option Explicit

' A ChangeVariable is needed for every 31 fields. It holds
' the bitmap for writing to the History Table.
Dim ChangeVariable1 As Long

Private Sub Category_AfterUpdate()
'Check to see if Category has changed from what it was
'when the record was brought in. If it changed, set the
'bit for the Category field. If it hasn't, clear the bit.
If txtCategoryOld <> Category Or IsNull(Category) Then
ChangeVariable1 = ChangeVariable1 Or cvCategory
Else
ChangeVariable1 = ChangeVariable1 And (AllBits - cvCategory)
End If
End Sub

Private Sub Form_AfterUpdate()
If ChangeVariable1 = 0 Then
Exit Sub ' Don't write a record
End If
WriteHistory ' Write a history record
End Sub



Public Sub WriteHistory()
Dim MsgResponse As Integer
MsgResponse = MsgBox("Add a Comment to this history record?", vbYesNo,
"History Routine Message")
If MsgResponse = vbYes Then
DoCmd.OpenForm "Frm_Comments", , , , , acDialog
End If
htrs.AddNew
htrs("ApplicationNumber") = ApplicationNumber
htrs("User") = fOSUserName
htrs("Date") = Now()
htrs("HistoryCode") = HistoryCode
htrs("FieldsUpdated1") = ChangeVariable1
htrs("Comments") = CurrentComments
htrs.Update
htrs.Bookmark = htrs.LastModified
CurrentComments = ""
End Sub

On another form I assign the follow code

Private Sub cmdDetails_Click()
Dim Ckval As Long
Dim Endval As Long
Dim Testval As Long
Dim Fldcount As Integer
Dim FieldList As String
Fldcount = 0
FieldList = ""
Endval = HighFlag1
Testval = [FieldsUpdated1]
Ckval = &H1 'Start at the beginning
Do While (Ckval < Endval)
If (Ckval And Testval) Then
Fldcount = Fldcount + 1
FieldList = FieldList & FillString1(Ckval) & vbCrLf
End If
Ckval = Ckval + Ckval
Loop
If Fldcount = 0 Then
MsgBox "There were no fields changed." & vbCrLf & vbCrLf & "By: " &
[User]
Else
MsgBox "This history was written with the following fields changed:
" _
& vbCrLf & FieldList & vbCrLf & "By: " & [User]
End If
End Sub

Public Function FillString1(Ckval As Long) As String
Select Case Ckval
Case &H1
FillString1 = "Pillar"
Case &H2
FillString1 = "Category"
Case &H4
FillString1 = "ProjeactTitle"
Case &H8
FillString1 = "OrigResearchLocation"
Case &H16
FillString1 = "InstitutionPaid"
Case &H32
FillString1 = "HealthAuthority"
Case &H64
FillString1 = "UniversityAffiliation"
Case &H128
FillString1 = "RecruitmentStatus"
Case &H256
FillString1 = "FundingStatus"
Case &H512
FillString1 = "Declined"
Case &H1024
FillString1 = "FundingAgency"
Case &H2048
FillString1 = "FundingType"
Case &H4096
FillString1 = "FundingAmount"
Case &H8192
FillString1 = "StartDate"
Case &H16384
FillString1 = "EndDate"
End Select

End Function
 
Back
Top